From 4d6c4a3e22dadaab89a1fded92a0423b1ca9f035 Mon Sep 17 00:00:00 2001 From: mlippautz Date: Tue, 15 Sep 2015 07:58:44 -0700 Subject: [PATCH] Add barriers to atomic utils. Loads get an acquire, store/cas a release. Increment gets a full barrier. R=hpayer@chromium.org BUG= Review URL: https://codereview.chromium.org/1343883004 Cr-Commit-Position: refs/heads/master@{#30751} --- src/atomic-utils.h | 22 ++++++++++------------ test/unittests/atomic-utils-unittest.cc | 4 ++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/atomic-utils.h b/src/atomic-utils.h index 8e11833..2aa78f8 100644 --- a/src/atomic-utils.h +++ b/src/atomic-utils.h @@ -20,14 +20,14 @@ class AtomicNumber { explicit AtomicNumber(T initial) : value_(initial) {} V8_INLINE void Increment(T increment) { - base::NoBarrier_AtomicIncrement(&value_, - static_cast(increment)); + base::Barrier_AtomicIncrement(&value_, + static_cast(increment)); } - V8_INLINE T Value() { return static_cast(base::NoBarrier_Load(&value_)); } + V8_INLINE T Value() { return static_cast(base::Acquire_Load(&value_)); } V8_INLINE void SetValue(T new_value) { - base::NoBarrier_Store(&value_, static_cast(new_value)); + base::Release_Store(&value_, static_cast(new_value)); } V8_INLINE T operator=(T value) { @@ -52,19 +52,18 @@ class AtomicValue { : value_(cast_helper::to_storage_type(initial)) {} V8_INLINE T Value() { - return cast_helper::to_return_type(base::NoBarrier_Load(&value_)); + return cast_helper::to_return_type(base::Acquire_Load(&value_)); } V8_INLINE bool TrySetValue(T old_value, T new_value) { - return base::NoBarrier_CompareAndSwap( + return base::Release_CompareAndSwap( &value_, cast_helper::to_storage_type(old_value), cast_helper::to_storage_type(new_value)) == cast_helper::to_storage_type(old_value); } - V8_INLINE T /*old_value*/ SetValue(T new_value) { - return cast_helper::to_return_type(base::NoBarrier_AtomicExchange( - &value_, cast_helper::to_storage_type(new_value))); + V8_INLINE void SetValue(T new_value) { + base::Release_Store(&value_, cast_helper::to_storage_type(new_value)); } private: @@ -109,12 +108,11 @@ class AtomicEnumSet { bool IsEmpty() const { return ToIntegral() == 0; } bool Contains(E element) const { return (ToIntegral() & Mask(element)) != 0; } - bool ContainsAnyOf(const AtomicEnumSet& set) const { return (ToIntegral() & set.ToIntegral()) != 0; } - void RemoveAll() { base::NoBarrier_Store(&bits_, 0); } + void RemoveAll() { base::Release_Store(&bits_, 0); } bool operator==(const AtomicEnumSet& set) const { return ToIntegral() == set.ToIntegral(); @@ -160,7 +158,7 @@ class AtomicEnumSet { STATIC_ASSERT(E::kLastValue < (sizeof(base::AtomicWord) * CHAR_BIT)); V8_INLINE base::AtomicWord ToIntegral() const { - return base::NoBarrier_Load(&bits_); + return base::Acquire_Load(&bits_); } V8_INLINE base::AtomicWord Mask(E element) const { diff --git a/test/unittests/atomic-utils-unittest.cc b/test/unittests/atomic-utils-unittest.cc index a0d8a6a..ad33853 100644 --- a/test/unittests/atomic-utils-unittest.cc +++ b/test/unittests/atomic-utils-unittest.cc @@ -86,7 +86,7 @@ TEST(AtomicValue, TrySetValue) { TEST(AtomicValue, SetValue) { AtomicValue a(kB); - EXPECT_EQ(kB, a.SetValue(kC)); + a.SetValue(kC); EXPECT_EQ(TestFlag::kC, a.Value()); } @@ -95,7 +95,7 @@ TEST(AtomicValue, WithVoidStar) { AtomicValue a(nullptr); AtomicValue dummy(nullptr); EXPECT_EQ(nullptr, a.Value()); - EXPECT_EQ(nullptr, a.SetValue(&a)); + a.SetValue(&a); EXPECT_EQ(&a, a.Value()); EXPECT_FALSE(a.TrySetValue(nullptr, &dummy)); EXPECT_TRUE(a.TrySetValue(&a, &dummy)); -- 2.7.4