OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium 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 #include "base/atomicops.h" | 5 #include "base/atomicops.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 #define NUM_BITS(T) (sizeof(T) * 8) | 82 #define NUM_BITS(T) (sizeof(T) * 8) |
83 | 83 |
84 | 84 |
85 template <class AtomicType> | 85 template <class AtomicType> |
86 static void TestCompareAndSwap() { | 86 static void TestCompareAndSwap() { |
87 AtomicType value = 0; | 87 AtomicType value = 0; |
88 AtomicType prev = base::subtle::NoBarrier_CompareAndSwap(&value, 0, 1); | 88 AtomicType prev = base::subtle::NoBarrier_CompareAndSwap(&value, 0, 1); |
89 EXPECT_EQ(1, value); | 89 EXPECT_EQ(1, value); |
90 EXPECT_EQ(0, prev); | 90 EXPECT_EQ(0, prev); |
91 | 91 |
92 AtomicType fail = base::subtle::NoBarrier_CompareAndSwap(&value, 0, 2); | |
Alexander Potapenko
2015/11/02 19:40:53
I suggest you commit this change separately, it re
| |
93 EXPECT_EQ(1, value); | |
94 EXPECT_EQ(1, fail); | |
95 | |
92 // Use test value that has non-zero bits in both halves, more for testing | 96 // Use test value that has non-zero bits in both halves, more for testing |
93 // 64-bit implementation on 32-bit platforms. | 97 // 64-bit implementation on 32-bit platforms. |
94 const AtomicType k_test_val = (static_cast<uint64_t>(1) << | 98 const AtomicType k_test_val = (static_cast<uint64_t>(1) << |
95 (NUM_BITS(AtomicType) - 2)) + 11; | 99 (NUM_BITS(AtomicType) - 2)) + 11; |
96 value = k_test_val; | 100 value = k_test_val; |
97 prev = base::subtle::NoBarrier_CompareAndSwap(&value, 0, 5); | 101 prev = base::subtle::NoBarrier_CompareAndSwap(&value, 0, 5); |
98 EXPECT_EQ(k_test_val, value); | 102 EXPECT_EQ(k_test_val, value); |
99 EXPECT_EQ(k_test_val, prev); | 103 EXPECT_EQ(k_test_val, prev); |
100 | 104 |
101 value = k_test_val; | 105 value = k_test_val; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 | 236 |
233 TEST(AtomicOpsTest, Store) { | 237 TEST(AtomicOpsTest, Store) { |
234 TestStore<base::subtle::Atomic32>(); | 238 TestStore<base::subtle::Atomic32>(); |
235 TestStore<base::subtle::AtomicWord>(); | 239 TestStore<base::subtle::AtomicWord>(); |
236 } | 240 } |
237 | 241 |
238 TEST(AtomicOpsTest, Load) { | 242 TEST(AtomicOpsTest, Load) { |
239 TestLoad<base::subtle::Atomic32>(); | 243 TestLoad<base::subtle::Atomic32>(); |
240 TestLoad<base::subtle::AtomicWord>(); | 244 TestLoad<base::subtle::AtomicWord>(); |
241 } | 245 } |
OLD | NEW |