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

Side by Side Diff: test/unittests/base/platform/condition-variable-unittest.cc

Issue 1412223018: [presubmit] Enabling readability/inheritance linter checking. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressing comments 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project 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 "src/base/platform/condition-variable.h" 5 #include "src/base/platform/condition-variable.h"
6 6
7 #include "src/base/platform/platform.h" 7 #include "src/base/platform/platform.h"
8 #include "src/base/platform/time.h" 8 #include "src/base/platform/time.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 17 matching lines...) Expand all
28 28
29 29
30 namespace { 30 namespace {
31 31
32 class ThreadWithMutexAndConditionVariable final : public Thread { 32 class ThreadWithMutexAndConditionVariable final : public Thread {
33 public: 33 public:
34 ThreadWithMutexAndConditionVariable() 34 ThreadWithMutexAndConditionVariable()
35 : Thread(Options("ThreadWithMutexAndConditionVariable")), 35 : Thread(Options("ThreadWithMutexAndConditionVariable")),
36 running_(false), 36 running_(false),
37 finished_(false) {} 37 finished_(false) {}
38 virtual ~ThreadWithMutexAndConditionVariable() {}
39 38
40 virtual void Run() override { 39 void Run() override {
41 LockGuard<Mutex> lock_guard(&mutex_); 40 LockGuard<Mutex> lock_guard(&mutex_);
42 running_ = true; 41 running_ = true;
43 cv_.NotifyOne(); 42 cv_.NotifyOne();
44 while (running_) { 43 while (running_) {
45 cv_.Wait(&mutex_); 44 cv_.Wait(&mutex_);
46 } 45 }
47 finished_ = true; 46 finished_ = true;
48 cv_.NotifyAll(); 47 cv_.NotifyAll();
49 } 48 }
50 49
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 namespace { 108 namespace {
110 109
111 class ThreadWithSharedMutexAndConditionVariable final : public Thread { 110 class ThreadWithSharedMutexAndConditionVariable final : public Thread {
112 public: 111 public:
113 ThreadWithSharedMutexAndConditionVariable() 112 ThreadWithSharedMutexAndConditionVariable()
114 : Thread(Options("ThreadWithSharedMutexAndConditionVariable")), 113 : Thread(Options("ThreadWithSharedMutexAndConditionVariable")),
115 running_(false), 114 running_(false),
116 finished_(false), 115 finished_(false),
117 cv_(NULL), 116 cv_(NULL),
118 mutex_(NULL) {} 117 mutex_(NULL) {}
119 virtual ~ThreadWithSharedMutexAndConditionVariable() {}
120 118
121 virtual void Run() override { 119 void Run() override {
122 LockGuard<Mutex> lock_guard(mutex_); 120 LockGuard<Mutex> lock_guard(mutex_);
123 running_ = true; 121 running_ = true;
124 cv_->NotifyAll(); 122 cv_->NotifyAll();
125 while (running_) { 123 while (running_) {
126 cv_->Wait(mutex_); 124 cv_->Wait(mutex_);
127 } 125 }
128 finished_ = true; 126 finished_ = true;
129 cv_->NotifyAll(); 127 cv_->NotifyAll();
130 } 128 }
131 129
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 rem_(rem), 224 rem_(rem),
227 counter_(counter), 225 counter_(counter),
228 limit_(limit), 226 limit_(limit),
229 thread_count_(thread_count), 227 thread_count_(thread_count),
230 cv_(cv), 228 cv_(cv),
231 mutex_(mutex) { 229 mutex_(mutex) {
232 EXPECT_LT(rem, thread_count); 230 EXPECT_LT(rem, thread_count);
233 EXPECT_EQ(0, limit % thread_count); 231 EXPECT_EQ(0, limit % thread_count);
234 } 232 }
235 233
236 virtual void Run() override { 234 void Run() override {
237 int last_count = -1; 235 int last_count = -1;
238 while (true) { 236 while (true) {
239 LockGuard<Mutex> lock_guard(mutex_); 237 LockGuard<Mutex> lock_guard(mutex_);
240 int count = *counter_; 238 int count = *counter_;
241 while (count % thread_count_ != rem_ && count < limit_) { 239 while (count % thread_count_ != rem_ && count < limit_) {
242 cv_->Wait(mutex_); 240 cv_->Wait(mutex_);
243 count = *counter_; 241 count = *counter_;
244 } 242 }
245 if (count >= limit_) break; 243 if (count >= limit_) break;
246 EXPECT_EQ(*counter_, count); 244 EXPECT_EQ(*counter_, count);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 delete threads[n]; 290 delete threads[n];
293 } 291 }
294 delete[] threads; 292 delete[] threads;
295 293
296 EXPECT_EQ(limit, counter); 294 EXPECT_EQ(limit, counter);
297 } 295 }
298 } 296 }
299 297
300 } // namespace base 298 } // namespace base
301 } // namespace v8 299 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-gap-resolver.cc ('k') | test/unittests/base/platform/semaphore-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698