| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 return cast_helper<T>::to_return_type(base::Acquire_Load(&value_)); | 65 return cast_helper<T>::to_return_type(base::Acquire_Load(&value_)); |
| 66 } | 66 } |
| 67 | 67 |
| 68 V8_INLINE bool TrySetValue(T old_value, T new_value) { | 68 V8_INLINE bool TrySetValue(T old_value, T new_value) { |
| 69 return base::Release_CompareAndSwap( | 69 return base::Release_CompareAndSwap( |
| 70 &value_, cast_helper<T>::to_storage_type(old_value), | 70 &value_, cast_helper<T>::to_storage_type(old_value), |
| 71 cast_helper<T>::to_storage_type(new_value)) == | 71 cast_helper<T>::to_storage_type(new_value)) == |
| 72 cast_helper<T>::to_storage_type(old_value); | 72 cast_helper<T>::to_storage_type(old_value); |
| 73 } | 73 } |
| 74 | 74 |
| 75 V8_INLINE void SetBits(T bits, T mask) { |
| 76 DCHECK_EQ(bits & ~mask, 0); |
| 77 T old_value; |
| 78 T new_value; |
| 79 do { |
| 80 old_value = Value(); |
| 81 new_value = (old_value & ~mask) | bits; |
| 82 } while (!TrySetValue(old_value, new_value)); |
| 83 } |
| 84 |
| 85 V8_INLINE void SetBit(int bit) { |
| 86 SetBits(static_cast<T>(1) << bit, static_cast<T>(1) << bit); |
| 87 } |
| 88 |
| 89 V8_INLINE void ClearBit(int bit) { SetBits(0, 1 << bit); } |
| 90 |
| 75 V8_INLINE void SetValue(T new_value) { | 91 V8_INLINE void SetValue(T new_value) { |
| 76 base::Release_Store(&value_, cast_helper<T>::to_storage_type(new_value)); | 92 base::Release_Store(&value_, cast_helper<T>::to_storage_type(new_value)); |
| 77 } | 93 } |
| 78 | 94 |
| 79 private: | 95 private: |
| 80 STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord)); | 96 STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord)); |
| 81 | 97 |
| 82 template <typename S> | 98 template <typename S> |
| 83 struct cast_helper { | 99 struct cast_helper { |
| 84 static base::AtomicWord to_storage_type(S value) { | 100 static base::AtomicWord to_storage_type(S value) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 return static_cast<base::AtomicWord>(1) << element; | 191 return static_cast<base::AtomicWord>(1) << element; |
| 176 } | 192 } |
| 177 | 193 |
| 178 base::AtomicWord bits_; | 194 base::AtomicWord bits_; |
| 179 }; | 195 }; |
| 180 | 196 |
| 181 } // namespace base | 197 } // namespace base |
| 182 } // namespace v8 | 198 } // namespace v8 |
| 183 | 199 |
| 184 #endif // #define V8_ATOMIC_UTILS_H_ | 200 #endif // #define V8_ATOMIC_UTILS_H_ |
| OLD | NEW |