diff options
| author | glider@chromium.org <glider@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-25 15:51:30 +0000 |
|---|---|---|
| committer | glider@chromium.org <glider@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-25 15:51:30 +0000 |
| commit | 4dd8c3e74a97deb3edf31f1ddf1195ea0ca27295 (patch) | |
| tree | c432fab0ee34d85cab5766fd21f285969648c0be /content/common/gamepad_seqlock_unittest.cc | |
| parent | 26eddafcdc87ef012c77f6ec4edecdef6f900f74 (diff) | |
| download | chromium_src-4dd8c3e74a97deb3edf31f1ddf1195ea0ca27295.zip chromium_src-4dd8c3e74a97deb3edf31f1ddf1195ea0ca27295.tar.gz chromium_src-4dd8c3e74a97deb3edf31f1ddf1195ea0ca27295.tar.bz2 | |
Revert 143903 - Lock-free GamepadSeqLock
The change
- provides an improved lock-free SeqLock implementation which eliminates any potential blocking of readers.
- provides a higher-level and simpler API as was suggested by Darin.
- ThreadSanitizer report suppressions are replaced with correct synchronization.
- eliminates nasty kMaximumContentionCount and associated histogram.
Review URL: https://chromiumcodereview.appspot.com/8772004
TBR=dvyukov@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10656020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/common/gamepad_seqlock_unittest.cc')
| -rw-r--r-- | content/common/gamepad_seqlock_unittest.cc | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/content/common/gamepad_seqlock_unittest.cc b/content/common/gamepad_seqlock_unittest.cc index cfd3b74..7e5da3f 100644 --- a/content/common/gamepad_seqlock_unittest.cc +++ b/content/common/gamepad_seqlock_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,6 +8,7 @@ #include "base/atomic_ref_count.h" #include "base/threading/platform_thread.h" +#include "base/third_party/dynamic_annotations/dynamic_annotations.h" #include "testing/gtest/include/gtest/gtest.h" namespace base { @@ -23,9 +24,11 @@ class BasicSeqLockTestThread : public PlatformThread::Delegate { BasicSeqLockTestThread() {} void Init( - content::GamepadSeqLock<TestData>* seqlock, + content::GamepadSeqLock* seqlock, + TestData* data, base::subtle::Atomic32* ready) { seqlock_ = seqlock; + data_ = data; ready_ = ready; } virtual void ThreadMain() { @@ -35,7 +38,12 @@ class BasicSeqLockTestThread : public PlatformThread::Delegate { for (unsigned i = 0; i < 1000; ++i) { TestData copy; - seqlock_->ReadTo(©); + base::subtle::Atomic32 version; + do { + version = seqlock_->ReadBegin(); + copy = *data_; + } while (seqlock_->ReadRetry(version)); + EXPECT_EQ(copy.a + 100, copy.b); EXPECT_EQ(copy.c, copy.b + copy.a); } @@ -44,33 +52,37 @@ class BasicSeqLockTestThread : public PlatformThread::Delegate { } private: - content::GamepadSeqLock<TestData>* seqlock_; + content::GamepadSeqLock* seqlock_; + TestData* data_; base::AtomicRefCount* ready_; DISALLOW_COPY_AND_ASSIGN(BasicSeqLockTestThread); }; TEST(GamepadSeqLockTest, ManyThreads) { - content::GamepadSeqLock<TestData> seqlock; + content::GamepadSeqLock seqlock; TestData data = { 0, 0, 0 }; base::AtomicRefCount ready = 0; + ANNOTATE_BENIGN_RACE_SIZED(&data, sizeof(data), "Racey reads are discarded"); + static const unsigned kNumReaderThreads = 10; BasicSeqLockTestThread threads[kNumReaderThreads]; PlatformThreadHandle handles[kNumReaderThreads]; for (unsigned i = 0; i < kNumReaderThreads; ++i) - threads[i].Init(&seqlock, &ready); + threads[i].Init(&seqlock, &data, &ready); for (unsigned i = 0; i < kNumReaderThreads; ++i) ASSERT_TRUE(PlatformThread::Create(0, &threads[i], &handles[i])); // The main thread is the writer, and the spawned are readers. unsigned counter = 0; for (;;) { + seqlock.WriteBegin(); data.a = counter++; data.b = data.a + 100; data.c = data.b + data.a; - seqlock.Write(data); + seqlock.WriteEnd(); if (counter == 1) base::AtomicRefCountIncN(&ready, kNumReaderThreads); |
