| 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" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 // Flag using T atomically. Also accepts void* as T. | 46 // Flag using T atomically. Also accepts void* as T. |
| 47 template <typename T> | 47 template <typename T> |
| 48 class AtomicValue { | 48 class AtomicValue { |
| 49 public: | 49 public: |
| 50 AtomicValue() : value_(0) {} | 50 AtomicValue() : value_(0) {} |
| 51 | 51 |
| 52 explicit AtomicValue(T initial) | 52 explicit AtomicValue(T initial) |
| 53 : value_(cast_helper<T>::to_storage_type(initial)) {} | 53 : value_(cast_helper<T>::to_storage_type(initial)) {} |
| 54 | 54 |
| 55 V8_INLINE T Value() { | 55 V8_INLINE T Value() const { |
| 56 return cast_helper<T>::to_return_type(base::Acquire_Load(&value_)); | 56 return cast_helper<T>::to_return_type(base::Acquire_Load(&value_)); |
| 57 } | 57 } |
| 58 | 58 |
| 59 V8_INLINE bool TrySetValue(T old_value, T new_value) { | 59 V8_INLINE bool TrySetValue(T old_value, T new_value) { |
| 60 return base::Release_CompareAndSwap( | 60 return base::Release_CompareAndSwap( |
| 61 &value_, cast_helper<T>::to_storage_type(old_value), | 61 &value_, cast_helper<T>::to_storage_type(old_value), |
| 62 cast_helper<T>::to_storage_type(new_value)) == | 62 cast_helper<T>::to_storage_type(new_value)) == |
| 63 cast_helper<T>::to_storage_type(old_value); | 63 cast_helper<T>::to_storage_type(old_value); |
| 64 } | 64 } |
| 65 | 65 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 return static_cast<base::AtomicWord>(1) << element; | 166 return static_cast<base::AtomicWord>(1) << element; |
| 167 } | 167 } |
| 168 | 168 |
| 169 base::AtomicWord bits_; | 169 base::AtomicWord bits_; |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 } // namespace base | 172 } // namespace base |
| 173 } // namespace v8 | 173 } // namespace v8 |
| 174 | 174 |
| 175 #endif // #define V8_ATOMIC_UTILS_H_ | 175 #endif // #define V8_ATOMIC_UTILS_H_ |
| OLD | NEW |