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

Unified Diff: content/common/one_writer_seqlock_unittest.cc

Issue 1164563003: Extract device_sensors to /device via Mojofication (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months 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
« no previous file with comments | « content/common/one_writer_seqlock.cc ('k') | content/common/shared_memory_seqlock_buffer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/one_writer_seqlock_unittest.cc
diff --git a/content/common/one_writer_seqlock_unittest.cc b/content/common/one_writer_seqlock_unittest.cc
deleted file mode 100644
index a72ab5d3b7be3a652b8f1078f5b46c40f72ace6a..0000000000000000000000000000000000000000
--- a/content/common/one_writer_seqlock_unittest.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-// 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.
-
-#include "content/common/one_writer_seqlock.h"
-
-#include <stdlib.h>
-
-#include "base/atomic_ref_count.h"
-#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
-#include "base/threading/platform_thread.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-
-// Basic test to make sure that basic operation works correctly.
-
-struct TestData {
- unsigned a, b, c;
-};
-
-class BasicSeqLockTestThread : public PlatformThread::Delegate {
- public:
- BasicSeqLockTestThread() {}
-
- void Init(
- content::OneWriterSeqLock* seqlock,
- TestData* data,
- base::subtle::Atomic32* ready) {
- seqlock_ = seqlock;
- data_ = data;
- ready_ = ready;
- }
- void ThreadMain() override {
- while (AtomicRefCountIsZero(ready_)) {
- PlatformThread::YieldCurrentThread();
- }
-
- for (unsigned i = 0; i < 1000; ++i) {
- TestData copy;
- 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);
- }
-
- AtomicRefCountDec(ready_);
- }
-
- private:
- content::OneWriterSeqLock* seqlock_;
- TestData* data_;
- base::AtomicRefCount* ready_;
-
- DISALLOW_COPY_AND_ASSIGN(BasicSeqLockTestThread);
-};
-
-TEST(OneWriterSeqLockTest, ManyThreads) {
- content::OneWriterSeqLock 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);
- 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();
-
- if (counter == 1)
- base::AtomicRefCountIncN(&ready, kNumReaderThreads);
-
- if (AtomicRefCountIsZero(&ready))
- break;
- }
-
- for (unsigned i = 0; i < kNumReaderThreads; ++i)
- PlatformThread::Join(handles[i]);
-}
-
-} // namespace base
« no previous file with comments | « content/common/one_writer_seqlock.cc ('k') | content/common/shared_memory_seqlock_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698