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

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

Issue 484643002: Version 3.28.71.3 (merged r23081) (Closed) Base URL: https://v8.googlecode.com/svn/branches/3.28
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/x87/lithium-x87.h ('k') | test/base-unittests/platform/platform-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 14 matching lines...) Expand all
25 EXPECT_FALSE(cv.WaitFor(&mutex, TimeDelta::FromMicroseconds(n))); 25 EXPECT_FALSE(cv.WaitFor(&mutex, TimeDelta::FromMicroseconds(n)));
26 } 26 }
27 } 27 }
28 28
29 29
30 namespace { 30 namespace {
31 31
32 class ThreadWithMutexAndConditionVariable V8_FINAL : public Thread { 32 class ThreadWithMutexAndConditionVariable V8_FINAL : public Thread {
33 public: 33 public:
34 ThreadWithMutexAndConditionVariable() 34 ThreadWithMutexAndConditionVariable()
35 : Thread("ThreadWithMutexAndConditionVariable"), 35 : Thread(Options("ThreadWithMutexAndConditionVariable")),
36 running_(false), finished_(false) {} 36 running_(false),
37 finished_(false) {}
37 virtual ~ThreadWithMutexAndConditionVariable() {} 38 virtual ~ThreadWithMutexAndConditionVariable() {}
38 39
39 virtual void Run() V8_OVERRIDE { 40 virtual void Run() V8_OVERRIDE {
40 LockGuard<Mutex> lock_guard(&mutex_); 41 LockGuard<Mutex> lock_guard(&mutex_);
41 running_ = true; 42 running_ = true;
42 cv_.NotifyOne(); 43 cv_.NotifyOne();
43 while (running_) { 44 while (running_) {
44 cv_.Wait(&mutex_); 45 cv_.Wait(&mutex_);
45 } 46 }
46 finished_ = true; 47 finished_ = true;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 EXPECT_TRUE(threads[n].finished_); 104 EXPECT_TRUE(threads[n].finished_);
104 } 105 }
105 } 106 }
106 107
107 108
108 namespace { 109 namespace {
109 110
110 class ThreadWithSharedMutexAndConditionVariable V8_FINAL : public Thread { 111 class ThreadWithSharedMutexAndConditionVariable V8_FINAL : public Thread {
111 public: 112 public:
112 ThreadWithSharedMutexAndConditionVariable() 113 ThreadWithSharedMutexAndConditionVariable()
113 : Thread("ThreadWithSharedMutexAndConditionVariable"), 114 : Thread(Options("ThreadWithSharedMutexAndConditionVariable")),
114 running_(false), finished_(false), cv_(NULL), mutex_(NULL) {} 115 running_(false),
116 finished_(false),
117 cv_(NULL),
118 mutex_(NULL) {}
115 virtual ~ThreadWithSharedMutexAndConditionVariable() {} 119 virtual ~ThreadWithSharedMutexAndConditionVariable() {}
116 120
117 virtual void Run() V8_OVERRIDE { 121 virtual void Run() V8_OVERRIDE {
118 LockGuard<Mutex> lock_guard(mutex_); 122 LockGuard<Mutex> lock_guard(mutex_);
119 running_ = true; 123 running_ = true;
120 cv_->NotifyAll(); 124 cv_->NotifyAll();
121 while (running_) { 125 while (running_) {
122 cv_->Wait(mutex_); 126 cv_->Wait(mutex_);
123 } 127 }
124 finished_ = true; 128 finished_ = true;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 for (int n = 0; n < kThreadCount; ++n) { 213 for (int n = 0; n < kThreadCount; ++n) {
210 threads[n].Join(); 214 threads[n].Join();
211 } 215 }
212 } 216 }
213 217
214 218
215 namespace { 219 namespace {
216 220
217 class LoopIncrementThread V8_FINAL : public Thread { 221 class LoopIncrementThread V8_FINAL : public Thread {
218 public: 222 public:
219 LoopIncrementThread(int rem, 223 LoopIncrementThread(int rem, int* counter, int limit, int thread_count,
220 int* counter, 224 ConditionVariable* cv, Mutex* mutex)
221 int limit, 225 : Thread(Options("LoopIncrementThread")),
222 int thread_count, 226 rem_(rem),
223 ConditionVariable* cv, 227 counter_(counter),
224 Mutex* mutex) 228 limit_(limit),
225 : Thread("LoopIncrementThread"), rem_(rem), counter_(counter), 229 thread_count_(thread_count),
226 limit_(limit), thread_count_(thread_count), cv_(cv), mutex_(mutex) { 230 cv_(cv),
231 mutex_(mutex) {
227 EXPECT_LT(rem, thread_count); 232 EXPECT_LT(rem, thread_count);
228 EXPECT_EQ(0, limit % thread_count); 233 EXPECT_EQ(0, limit % thread_count);
229 } 234 }
230 235
231 virtual void Run() V8_OVERRIDE { 236 virtual void Run() V8_OVERRIDE {
232 int last_count = -1; 237 int last_count = -1;
233 while (true) { 238 while (true) {
234 LockGuard<Mutex> lock_guard(mutex_); 239 LockGuard<Mutex> lock_guard(mutex_);
235 int count = *counter_; 240 int count = *counter_;
236 while (count % thread_count_ != rem_ && count < limit_) { 241 while (count % thread_count_ != rem_ && count < limit_) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 delete threads[n]; 292 delete threads[n];
288 } 293 }
289 delete[] threads; 294 delete[] threads;
290 295
291 EXPECT_EQ(limit, counter); 296 EXPECT_EQ(limit, counter);
292 } 297 }
293 } 298 }
294 299
295 } // namespace base 300 } // namespace base
296 } // namespace v8 301 } // namespace v8
OLDNEW
« no previous file with comments | « src/x87/lithium-x87.h ('k') | test/base-unittests/platform/platform-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698