Index: src/base/atomic-utils.h |
diff --git a/src/base/atomic-utils.h b/src/base/atomic-utils.h |
index 31db603bf94345bb84ce9ef7b135c513f8f9da3a..7931c7376ab4b5ba4bf27268bbeb124fec6acef8 100644 |
--- a/src/base/atomic-utils.h |
+++ b/src/base/atomic-utils.h |
@@ -51,6 +51,53 @@ class AtomicNumber { |
base::AtomicWord value_; |
}; |
+// This type uses no barrier accessors to change atomic word. Be careful with |
+// data races. |
+template <typename T> |
+class NoBarrierAtomicValue { |
+ public: |
+ NoBarrierAtomicValue() : value_(0) {} |
+ |
+ explicit NoBarrierAtomicValue(T initial) |
+ : value_(cast_helper<T>::to_storage_type(initial)) {} |
+ |
+ static NoBarrierAtomicValue* FromAddress(void* address) { |
+ return reinterpret_cast<base::NoBarrierAtomicValue<T>*>(address); |
+ } |
+ |
+ V8_INLINE T Value() const { |
+ return cast_helper<T>::to_return_type(base::NoBarrier_Load(&value_)); |
+ } |
+ |
+ V8_INLINE void SetValue(T new_value) { |
+ base::NoBarrier_Store(&value_, cast_helper<T>::to_storage_type(new_value)); |
+ } |
+ |
+ private: |
+ STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord)); |
+ |
+ template <typename S> |
+ struct cast_helper { |
+ static base::AtomicWord to_storage_type(S value) { |
+ return static_cast<base::AtomicWord>(value); |
+ } |
+ static S to_return_type(base::AtomicWord value) { |
+ return static_cast<S>(value); |
+ } |
+ }; |
+ |
+ template <typename S> |
+ struct cast_helper<S*> { |
+ static base::AtomicWord to_storage_type(S* value) { |
+ return reinterpret_cast<base::AtomicWord>(value); |
+ } |
+ static S* to_return_type(base::AtomicWord value) { |
+ return reinterpret_cast<S*>(value); |
+ } |
+ }; |
+ |
+ base::AtomicWord value_; |
+}; |
// Flag using T atomically. Also accepts void* as T. |
template <typename T> |