9 #include "testing/gtest/include/gtest/gtest.h"
14 TEST(ConditionVariable, WaitForAfterNofityOnSameThread) {
15 for (
int n = 0; n < 10; ++n) {
19 LockGuard<Mutex> lock_guard(&mutex);
22 EXPECT_FALSE(cv.WaitFor(&mutex, TimeDelta::FromMicroseconds(n)));
25 EXPECT_FALSE(cv.WaitFor(&mutex, TimeDelta::FromMicroseconds(n)));
32 class ThreadWithMutexAndConditionVariable
FINAL :
public Thread {
41 LockGuard<Mutex> lock_guard(&mutex_);
53 ConditionVariable
cv_;
60 TEST(ConditionVariable, MultipleThreadsWithSeparateConditionVariables) {
61 static const int kThreadCount = 128;
62 ThreadWithMutexAndConditionVariable threads[kThreadCount];
64 for (
int n = 0; n < kThreadCount; ++n) {
65 LockGuard<Mutex> lock_guard(&threads[n].mutex_);
66 EXPECT_FALSE(threads[n].running_);
67 EXPECT_FALSE(threads[n].finished_);
70 while (!threads[n].running_) {
71 threads[n].cv_.Wait(&threads[n].mutex_);
75 for (
int n = kThreadCount - 1; n >= 0; --n) {
76 LockGuard<Mutex> lock_guard(&threads[n].mutex_);
77 EXPECT_TRUE(threads[n].running_);
78 EXPECT_FALSE(threads[n].finished_);
81 for (
int n = 0; n < kThreadCount; ++n) {
82 LockGuard<Mutex> lock_guard(&threads[n].mutex_);
83 EXPECT_TRUE(threads[n].running_);
84 EXPECT_FALSE(threads[n].finished_);
86 threads[n].running_ =
false;
87 threads[n].cv_.NotifyOne();
90 for (
int n = kThreadCount - 1; n >= 0; --n) {
92 LockGuard<Mutex> lock_guard(&threads[n].mutex_);
93 while (!threads[n].finished_) {
94 threads[n].cv_.Wait(&threads[n].mutex_);
96 EXPECT_FALSE(threads[n].running_);
97 EXPECT_TRUE(threads[n].finished_);
100 for (
int n = 0; n < kThreadCount; ++n) {
102 LockGuard<Mutex> lock_guard(&threads[n].mutex_);
103 EXPECT_FALSE(threads[n].running_);
104 EXPECT_TRUE(threads[n].finished_);
111 class ThreadWithSharedMutexAndConditionVariable
FINAL :
public Thread {
114 :
Thread(
Options(
"ThreadWithSharedMutexAndConditionVariable")),
122 LockGuard<Mutex> lock_guard(mutex_);
141 TEST(ConditionVariable, MultipleThreadsWithSharedSeparateConditionVariables) {
142 static const int kThreadCount = 128;
143 ThreadWithSharedMutexAndConditionVariable threads[kThreadCount];
144 ConditionVariable cv;
147 for (
int n = 0; n < kThreadCount; ++n) {
148 threads[n].mutex_ = &mutex;
149 threads[n].cv_ = &cv;
154 LockGuard<Mutex> lock_guard(&mutex);
155 for (
int n = 0; n < kThreadCount; ++n) {
156 EXPECT_FALSE(threads[n].running_);
157 EXPECT_FALSE(threads[n].finished_);
164 LockGuard<Mutex> lock_guard(&mutex);
165 for (
int n = kThreadCount - 1; n >= 0; --n) {
166 while (!threads[n].running_) {
174 LockGuard<Mutex> lock_guard(&mutex);
175 for (
int n = 0; n < kThreadCount; ++n) {
176 EXPECT_TRUE(threads[n].running_);
177 EXPECT_FALSE(threads[n].finished_);
183 LockGuard<Mutex> lock_guard(&mutex);
184 for (
int n = kThreadCount - 1; n >= 0; --n) {
185 EXPECT_TRUE(threads[n].running_);
186 EXPECT_FALSE(threads[n].finished_);
188 threads[n].running_ =
false;
195 LockGuard<Mutex> lock_guard(&mutex);
196 for (
int n = 0; n < kThreadCount; ++n) {
197 while (!threads[n].finished_) {
205 LockGuard<Mutex> lock_guard(&mutex);
206 for (
int n = kThreadCount - 1; n >= 0; --n) {
207 EXPECT_FALSE(threads[n].running_);
208 EXPECT_TRUE(threads[n].finished_);
213 for (
int n = 0; n < kThreadCount; ++n) {
221 class LoopIncrementThread
FINAL :
public Thread {
224 ConditionVariable* cv, Mutex* mutex)
229 thread_count_(thread_count),
232 EXPECT_LT(rem, thread_count);
233 EXPECT_EQ(0, limit % thread_count);
239 LockGuard<Mutex> lock_guard(mutex_);
240 int count = *counter_;
241 while (count % thread_count_ != rem_ && count < limit_) {
245 if (count >= limit_)
break;
246 EXPECT_EQ(*counter_, count);
247 if (last_count != -1) {
248 EXPECT_EQ(last_count + (thread_count_ - 1), count);
262 ConditionVariable* cv_;
269 TEST(ConditionVariable, LoopIncrement) {
270 static const int kMaxThreadCount = 16;
272 ConditionVariable cv;
273 for (
int thread_count = 1; thread_count < kMaxThreadCount; ++thread_count) {
274 int limit = thread_count * 10;
279 for (
int n = 0; n < thread_count; ++n) {
280 threads[n] =
new LoopIncrementThread(n, &counter, limit, thread_count,
285 for (
int n = thread_count - 1; n >= 0; --n) {
290 for (
int n = 0; n < thread_count; ++n) {
296 EXPECT_EQ(limit, counter);
virtual ~ThreadWithMutexAndConditionVariable()
ThreadWithMutexAndConditionVariable()
virtual ~ThreadWithSharedMutexAndConditionVariable()
ThreadWithSharedMutexAndConditionVariable()
virtual void Run() OVERRIDE
LoopIncrementThread(int rem, int *counter, int limit, int thread_count, ConditionVariable *cv, Mutex *mutex)
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
TEST(CPUTest, FeatureImplications)
Debugger support for the V8 JavaScript engine.