Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
atomic_int32.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_BASE_ATOMIC_INT32_H_
20 #define PAGESPEED_KERNEL_BASE_ATOMIC_INT32_H_
21 
24 
25 namespace net_instaweb {
26 
72 class AtomicInt32 {
73  public:
74  explicit AtomicInt32(int32 value) {
75  set_value(value);
76  }
77  AtomicInt32() {
78  set_value(0);
79  }
80  ~AtomicInt32() {}
81 
83  int32 value() const {
84  return base::subtle::Acquire_Load(&value_);
85  }
86 
88  void set_value(int32 value) {
89  base::subtle::Release_Store(&value_, value);
90  }
91 
95  int32 NoBarrierIncrement(int32 amount) {
96  return base::subtle::NoBarrier_AtomicIncrement(&value_, amount);
97  }
98 
101  int32 BarrierIncrement(int32 amount) {
102  return base::subtle::Barrier_AtomicIncrement(&value_, amount);
103  }
104 
115  int32 CompareAndSwap(int32 expected_value, int32 new_value) {
116  return base::subtle::Release_CompareAndSwap(
117  &value_, expected_value, new_value);
118  }
119 
120  private:
121  base::subtle::AtomicWord value_;
122 
123 };
124 
125 }
126 
127 #endif
int32 BarrierIncrement(int32 amount)
Definition: atomic_int32.h:101
Definition: atomic_int32.h:72
void set_value(int32 value)
Store value. Has release semantics (see above).
Definition: atomic_int32.h:88
int32 NoBarrierIncrement(int32 amount)
Definition: atomic_int32.h:95
int32 value() const
Return the value currently stored. Has acquire semantics (see above).
Definition: atomic_int32.h:83
int32 CompareAndSwap(int32 expected_value, int32 new_value)
Definition: atomic_int32.h:115