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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 public: | 58 public: |
59 NoBarrierAtomicValue() : value_(0) {} | 59 NoBarrierAtomicValue() : value_(0) {} |
60 | 60 |
61 explicit NoBarrierAtomicValue(T initial) | 61 explicit NoBarrierAtomicValue(T initial) |
62 : value_(cast_helper<T>::to_storage_type(initial)) {} | 62 : value_(cast_helper<T>::to_storage_type(initial)) {} |
63 | 63 |
64 static NoBarrierAtomicValue* FromAddress(void* address) { | 64 static NoBarrierAtomicValue* FromAddress(void* address) { |
65 return reinterpret_cast<base::NoBarrierAtomicValue<T>*>(address); | 65 return reinterpret_cast<base::NoBarrierAtomicValue<T>*>(address); |
66 } | 66 } |
67 | 67 |
| 68 V8_INLINE bool TrySetValue(T old_value, T new_value) { |
| 69 return base::NoBarrier_CompareAndSwap( |
| 70 &value_, cast_helper<T>::to_storage_type(old_value), |
| 71 cast_helper<T>::to_storage_type(new_value)) == |
| 72 cast_helper<T>::to_storage_type(old_value); |
| 73 } |
| 74 |
68 V8_INLINE T Value() const { | 75 V8_INLINE T Value() const { |
69 return cast_helper<T>::to_return_type(base::NoBarrier_Load(&value_)); | 76 return cast_helper<T>::to_return_type(base::NoBarrier_Load(&value_)); |
70 } | 77 } |
71 | 78 |
72 V8_INLINE void SetValue(T new_value) { | 79 V8_INLINE void SetValue(T new_value) { |
73 base::NoBarrier_Store(&value_, cast_helper<T>::to_storage_type(new_value)); | 80 base::NoBarrier_Store(&value_, cast_helper<T>::to_storage_type(new_value)); |
74 } | 81 } |
75 | 82 |
76 private: | 83 private: |
77 STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord)); | 84 STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord)); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 return static_cast<base::AtomicWord>(1) << element; | 245 return static_cast<base::AtomicWord>(1) << element; |
239 } | 246 } |
240 | 247 |
241 base::AtomicWord bits_; | 248 base::AtomicWord bits_; |
242 }; | 249 }; |
243 | 250 |
244 } // namespace base | 251 } // namespace base |
245 } // namespace v8 | 252 } // namespace v8 |
246 | 253 |
247 #endif // #define V8_ATOMIC_UTILS_H_ | 254 #endif // #define V8_ATOMIC_UTILS_H_ |
OLD | NEW |