Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: base/atomicops_unittest.cc

Issue 1410213004: Create "persistent memory allocator" for persisting and sharing objects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moved flags to Atomic32 Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/base.gyp » ('j') | base/memory/shared_memory_allocator.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | base/base.gyp » ('j') | base/memory/shared_memory_allocator.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698