Index: src/base/atomic-utils.h |
diff --git a/src/base/atomic-utils.h b/src/base/atomic-utils.h |
index 31db603bf94345bb84ce9ef7b135c513f8f9da3a..f046ab9164e622d92b1642f53831a01d718d4ec7 100644 |
--- a/src/base/atomic-utils.h |
+++ b/src/base/atomic-utils.h |
@@ -51,6 +51,49 @@ class AtomicNumber { |
base::AtomicWord value_; |
}; |
+// This type uses no barrier accessors to change atomic value. Be careful with |
+// data races. |
+template <typename T> |
+class NonAtomicValue { |
Michael Lippautz
2016/10/12 08:04:15
You sure about this name?
I'd rather call it NoBa
ulan
2016/10/12 08:32:39
+1 to NoBarrierAtomicValue
Hannes Payer (out of office)
2016/10/12 11:27:45
Changed the name. Note that the no barrier accesso
|
+ public: |
+ NonAtomicValue() : value_(0) {} |
+ |
+ explicit NonAtomicValue(T initial) |
+ : value_(cast_helper<T>::to_storage_type(initial)) {} |
+ |
+ 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> |