| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_ATOMIC_UTILS_H_ | 5 #ifndef V8_ATOMIC_UTILS_H_ |
| 6 #define V8_ATOMIC_UTILS_H_ | 6 #define V8_ATOMIC_UTILS_H_ |
| 7 | 7 |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 | 9 |
| 10 #include "src/base/atomicops.h" | 10 #include "src/base/atomicops.h" |
| 11 #include "src/base/macros.h" | 11 #include "src/base/macros.h" |
| 12 | 12 |
| 13 namespace v8 { | 13 namespace v8 { |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 template <class T> | 16 template <class T> |
| 17 class AtomicNumber { | 17 class AtomicNumber { |
| 18 public: | 18 public: |
| 19 AtomicNumber() : value_(0) {} | 19 AtomicNumber() : value_(0) {} |
| 20 explicit AtomicNumber(T initial) : value_(initial) {} | 20 explicit AtomicNumber(T initial) : value_(initial) {} |
| 21 | 21 |
| 22 V8_INLINE void Increment(T increment) { | 22 // Returns the newly set value. |
| 23 base::Barrier_AtomicIncrement(&value_, | 23 V8_INLINE T Increment(T increment) { |
| 24 static_cast<base::AtomicWord>(increment)); | 24 return static_cast<T>(base::Barrier_AtomicIncrement( |
| 25 &value_, static_cast<base::AtomicWord>(increment))); |
| 25 } | 26 } |
| 26 | 27 |
| 27 V8_INLINE T Value() { return static_cast<T>(base::Acquire_Load(&value_)); } | 28 V8_INLINE T Value() { return static_cast<T>(base::Acquire_Load(&value_)); } |
| 28 | 29 |
| 29 V8_INLINE void SetValue(T new_value) { | 30 V8_INLINE void SetValue(T new_value) { |
| 30 base::Release_Store(&value_, static_cast<base::AtomicWord>(new_value)); | 31 base::Release_Store(&value_, static_cast<base::AtomicWord>(new_value)); |
| 31 } | 32 } |
| 32 | 33 |
| 33 V8_INLINE T operator=(T value) { | 34 V8_INLINE T operator=(T value) { |
| 34 SetValue(value); | 35 SetValue(value); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return static_cast<base::AtomicWord>(1) << element; | 166 return static_cast<base::AtomicWord>(1) << element; |
| 166 } | 167 } |
| 167 | 168 |
| 168 base::AtomicWord bits_; | 169 base::AtomicWord bits_; |
| 169 }; | 170 }; |
| 170 | 171 |
| 171 } // namespace internal | 172 } // namespace internal |
| 172 } // namespace v8 | 173 } // namespace v8 |
| 173 | 174 |
| 174 #endif // #define V8_ATOMIC_UTILS_H_ | 175 #endif // #define V8_ATOMIC_UTILS_H_ |
| OLD | NEW |