| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 NoBarrierAtomicValue() : value_(0) {} | 61 NoBarrierAtomicValue() : value_(0) {} |
| 62 | 62 |
| 63 explicit NoBarrierAtomicValue(T initial) | 63 explicit NoBarrierAtomicValue(T initial) |
| 64 : value_(cast_helper<T>::to_storage_type(initial)) {} | 64 : value_(cast_helper<T>::to_storage_type(initial)) {} |
| 65 | 65 |
| 66 static NoBarrierAtomicValue* FromAddress(void* address) { | 66 static NoBarrierAtomicValue* FromAddress(void* address) { |
| 67 return reinterpret_cast<base::NoBarrierAtomicValue<T>*>(address); | 67 return reinterpret_cast<base::NoBarrierAtomicValue<T>*>(address); |
| 68 } | 68 } |
| 69 | 69 |
| 70 V8_INLINE bool TrySetValue(T old_value, T new_value) { | 70 V8_INLINE bool TrySetValue(T old_value, T new_value) { |
| 71 return base::NoBarrier_CompareAndSwap( | 71 return base::Relaxed_CompareAndSwap( |
| 72 &value_, cast_helper<T>::to_storage_type(old_value), | 72 &value_, cast_helper<T>::to_storage_type(old_value), |
| 73 cast_helper<T>::to_storage_type(new_value)) == | 73 cast_helper<T>::to_storage_type(new_value)) == |
| 74 cast_helper<T>::to_storage_type(old_value); | 74 cast_helper<T>::to_storage_type(old_value); |
| 75 } | 75 } |
| 76 | 76 |
| 77 V8_INLINE T Value() const { | 77 V8_INLINE T Value() const { |
| 78 return cast_helper<T>::to_return_type(base::NoBarrier_Load(&value_)); | 78 return cast_helper<T>::to_return_type(base::Relaxed_Load(&value_)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 V8_INLINE void SetValue(T new_value) { | 81 V8_INLINE void SetValue(T new_value) { |
| 82 base::NoBarrier_Store(&value_, cast_helper<T>::to_storage_type(new_value)); | 82 base::Relaxed_Store(&value_, cast_helper<T>::to_storage_type(new_value)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord)); | 86 STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord)); |
| 87 | 87 |
| 88 template <typename S> | 88 template <typename S> |
| 89 struct cast_helper { | 89 struct cast_helper { |
| 90 static base::AtomicWord to_storage_type(S value) { | 90 static base::AtomicWord to_storage_type(S value) { |
| 91 return static_cast<base::AtomicWord>(value); | 91 return static_cast<base::AtomicWord>(value); |
| 92 } | 92 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 return static_cast<base::AtomicWord>(1) << element; | 247 return static_cast<base::AtomicWord>(1) << element; |
| 248 } | 248 } |
| 249 | 249 |
| 250 base::AtomicWord bits_; | 250 base::AtomicWord bits_; |
| 251 }; | 251 }; |
| 252 | 252 |
| 253 } // namespace base | 253 } // namespace base |
| 254 } // namespace v8 | 254 } // namespace v8 |
| 255 | 255 |
| 256 #endif // #define V8_ATOMIC_UTILS_H_ | 256 #endif // #define V8_ATOMIC_UTILS_H_ |
| OLD | NEW |