Index: src/atomic-utils.h |
diff --git a/src/atomic-utils.h b/src/atomic-utils.h |
index cbdee04fc83c92151a17bb0575061d0ac6dd3cb6..3ba3dc98c17ac66135355c6076e634bc838669a3 100644 |
--- a/src/atomic-utils.h |
+++ b/src/atomic-utils.h |
@@ -13,22 +13,26 @@ |
namespace v8 { |
namespace internal { |
+template <class T> |
Michael Lippautz
2015/09/04 11:09:32
I don't think we need the storage type, as it shou
|
class AtomicValue { |
Michael Lippautz
2015/09/04 13:03:52
This one is now AtomicNumber
|
public: |
AtomicValue() : value_(0) {} |
- explicit AtomicValue(base::AtomicWord initial) : value_(initial) {} |
+ explicit AtomicValue(T initial) : value_(initial) {} |
- V8_INLINE void Increment(base::AtomicWord increment) { |
- base::NoBarrier_AtomicIncrement(&value_, increment); |
+ V8_INLINE void Increment(T increment) { |
+ base::NoBarrier_AtomicIncrement(&value_, |
+ static_cast<base::AtomicWord>(increment)); |
} |
- V8_INLINE base::AtomicWord Value() { return base::NoBarrier_Load(&value_); } |
+ V8_INLINE T Value() { return static_cast<T>(base::NoBarrier_Load(&value_)); } |
- V8_INLINE void SetValue(base::AtomicWord new_value) { |
- base::NoBarrier_Store(&value_, new_value); |
+ V8_INLINE void SetValue(T new_value) { |
+ base::NoBarrier_Store(&value_, static_cast<base::AtomicWord>(new_value)); |
} |
private: |
+ STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord)); |
+ |
base::AtomicWord value_; |
}; |
@@ -82,7 +86,7 @@ class AtomicEnumSet { |
void Add(const AtomicEnumSet& set) { ATOMIC_SET_WRITE(|, set.ToIntegral()); } |
- void Remove(E element) { ATOMIC_SET_WRITE(&, Mask(element)); } |
+ void Remove(E element) { ATOMIC_SET_WRITE(&, ~Mask(element)); } |
Michael Lippautz
2015/09/04 11:09:32
*duck*
|
void Remove(const AtomicEnumSet& set) { |
ATOMIC_SET_WRITE(&, ~set.ToIntegral()); |
@@ -110,22 +114,32 @@ class AtomicEnumSet { |
}; |
-// Flag using enums atomically. |
-template <class E> |
-class AtomicEnumFlag { |
+// Flag using T atomically. Also accepts void* as T. |
+template <typename T> |
+class AtomicFlag { |
Michael Lippautz
2015/09/04 11:09:32
Maybe another name would fit better.
Michael Starzinger
2015/09/04 11:43:19
Yeah, the name is misleading. How about "AtomicVar
Michael Lippautz
2015/09/04 13:03:52
AtomicValue it is.
|
public: |
- explicit AtomicEnumFlag(E initial) : value_(initial) {} |
+ explicit AtomicFlag(T initial) : value_((base::AtomicWord)initial) {} |
+ |
+ V8_INLINE T Value() { |
+ // We cannot use static_cast to cast from AtomicWord to void*, although |
+ // we guarantee that the storage is large enough. |
+ return (T)(base::NoBarrier_Load(&value_)); |
Michael Lippautz
2015/09/04 11:09:32
This is a bit unfortunate but I think AtomicFlag<v
Michael Starzinger
2015/09/04 11:43:19
This is uncool. Need to think more about that.
Michael Lippautz
2015/09/04 13:03:52
See the new "solution" (I know this is the wrong w
|
+ } |
- V8_INLINE E Value() { return static_cast<E>(base::NoBarrier_Load(&value_)); } |
+ V8_INLINE bool TrySetValue(T old_value, T new_value) { |
+ return base::NoBarrier_CompareAndSwap(&value_, (base::AtomicWord)old_value, |
+ (base::AtomicWord)new_value) == |
+ ((base::AtomicWord)old_value); |
+ } |
- V8_INLINE bool TrySetValue(E old_value, E new_value) { |
- return base::NoBarrier_CompareAndSwap( |
- &value_, static_cast<base::AtomicWord>(old_value), |
- static_cast<base::AtomicWord>(new_value)) == |
- static_cast<base::AtomicWord>(old_value); |
+ V8_INLINE T /*old_value*/ SetValue(T new_value) { |
+ return (T)base::NoBarrier_AtomicExchange(&value_, |
+ (base::AtomicWord)new_value); |
} |
private: |
+ STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord)); |
+ |
base::AtomicWord value_; |
}; |