diff options
author | bcwhite <bcwhite@chromium.org> | 2015-11-03 10:19:06 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-03 18:20:22 +0000 |
commit | 85c5a0a91d503d4cf4b5101ec0c83e9299f7074b (patch) | |
tree | 483fd54419d045c2381b3ac39e95aab002d86ff5 /base | |
parent | 16b9a9b067f3de540359fefbf1d79c7c25905781 (diff) | |
download | chromium_src-85c5a0a91d503d4cf4b5101ec0c83e9299f7074b.zip chromium_src-85c5a0a91d503d4cf4b5101ec0c83e9299f7074b.tar.gz chromium_src-85c5a0a91d503d4cf4b5101ec0c83e9299f7074b.tar.bz2 |
Add negative test case for CompareAndSwap.
Make sure that CompareAndSwap isn't doing things when it shouldn't. This
also doubles as an example of how to detect "failure" if someone
is trying to figure out how to use CompareAndSwap.
BUG=
Review URL: https://codereview.chromium.org/1410713009
Cr-Commit-Position: refs/heads/master@{#357555}
Diffstat (limited to 'base')
-rw-r--r-- | base/atomicops_unittest.cc | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/base/atomicops_unittest.cc b/base/atomicops_unittest.cc index 3fd5597..7298609 100644 --- a/base/atomicops_unittest.cc +++ b/base/atomicops_unittest.cc @@ -89,6 +89,13 @@ static void TestCompareAndSwap() { EXPECT_EQ(1, value); EXPECT_EQ(0, prev); + // Verify that CAS will *not* change "value" if it doesn't match the + // expected number. CAS will always return the actual value of the + // variable from before any change. + AtomicType fail = base::subtle::NoBarrier_CompareAndSwap(&value, 0, 2); + EXPECT_EQ(1, value); + EXPECT_EQ(1, fail); + // Use test value that has non-zero bits in both halves, more for testing // 64-bit implementation on 32-bit platforms. const AtomicType k_test_val = (static_cast<uint64_t>(1) << |