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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 120 } |
121 | 121 |
122 V8_INLINE bool TrySetValue(T old_value, T new_value) { | 122 V8_INLINE bool TrySetValue(T old_value, T new_value) { |
123 return base::Release_CompareAndSwap( | 123 return base::Release_CompareAndSwap( |
124 &value_, cast_helper<T>::to_storage_type(old_value), | 124 &value_, cast_helper<T>::to_storage_type(old_value), |
125 cast_helper<T>::to_storage_type(new_value)) == | 125 cast_helper<T>::to_storage_type(new_value)) == |
126 cast_helper<T>::to_storage_type(old_value); | 126 cast_helper<T>::to_storage_type(old_value); |
127 } | 127 } |
128 | 128 |
129 V8_INLINE void SetBits(T bits, T mask) { | 129 V8_INLINE void SetBits(T bits, T mask) { |
130 DCHECK_EQ(bits & ~mask, 0); | 130 DCHECK_EQ(bits & ~mask, static_cast<T>(0)); |
131 T old_value; | 131 T old_value; |
132 T new_value; | 132 T new_value; |
133 do { | 133 do { |
134 old_value = Value(); | 134 old_value = Value(); |
135 new_value = (old_value & ~mask) | bits; | 135 new_value = (old_value & ~mask) | bits; |
136 } while (!TrySetValue(old_value, new_value)); | 136 } while (!TrySetValue(old_value, new_value)); |
137 } | 137 } |
138 | 138 |
139 V8_INLINE void SetBit(int bit) { | 139 V8_INLINE void SetBit(int bit) { |
140 SetBits(static_cast<T>(1) << bit, static_cast<T>(1) << bit); | 140 SetBits(static_cast<T>(1) << bit, static_cast<T>(1) << bit); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 return static_cast<base::AtomicWord>(1) << element; | 245 return static_cast<base::AtomicWord>(1) << element; |
246 } | 246 } |
247 | 247 |
248 base::AtomicWord bits_; | 248 base::AtomicWord bits_; |
249 }; | 249 }; |
250 | 250 |
251 } // namespace base | 251 } // namespace base |
252 } // namespace v8 | 252 } // namespace v8 |
253 | 253 |
254 #endif // #define V8_ATOMIC_UTILS_H_ | 254 #endif // #define V8_ATOMIC_UTILS_H_ |
OLD | NEW |