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

Unified Diff: content/common/gamepad_seqlock_unittest.cc

Issue 8772004: Improve GamepadSeqLock impl Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gamepad_seqlock_unittest.cc
===================================================================
--- content/common/gamepad_seqlock_unittest.cc (revision 112429)
+++ content/common/gamepad_seqlock_unittest.cc (working copy)
@@ -8,7 +8,6 @@
#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 {
@@ -24,11 +23,9 @@
BasicSeqLockTestThread() {}
void Init(
- content::GamepadSeqLock* seqlock,
- TestData* data,
+ content::GamepadSeqLock<TestData>* seqlock,
base::subtle::Atomic32* ready) {
seqlock_ = seqlock;
- data_ = data;
ready_ = ready;
}
virtual void ThreadMain() {
@@ -36,14 +33,9 @@
PlatformThread::YieldCurrentThread();
}
- for (unsigned i = 0; i < 1000; ++i) {
+ for (unsigned i = 0; i < 10000; ++i) {
TestData copy;
- base::subtle::Atomic32 version;
- do {
- version = seqlock_->ReadBegin();
- copy = *data_;
- } while (seqlock_->ReadRetry(version));
-
+ seqlock_->ReadTo(&copy);
EXPECT_EQ(copy.a + 100, copy.b);
EXPECT_EQ(copy.c, copy.b + copy.a);
}
@@ -52,37 +44,33 @@
}
private:
- content::GamepadSeqLock* seqlock_;
- TestData* data_;
+ content::GamepadSeqLock<TestData>* seqlock_;
base::AtomicRefCount* ready_;
DISALLOW_COPY_AND_ASSIGN(BasicSeqLockTestThread);
};
TEST(GamepadSeqLockTest, ManyThreads) {
- content::GamepadSeqLock seqlock;
+ content::GamepadSeqLock<TestData> 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, &data, &ready);
+ threads[i].Init(&seqlock, &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.WriteEnd();
+ seqlock.Write(&data);
if (counter == 1)
base::AtomicRefCountIncN(&ready, kNumReaderThreads);

Powered by Google App Engine
This is Rietveld 408576698