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

Side by Side Diff: runtime/vm/thread_pool_test.cc

Issue 9704037: Another fix for non-mac build: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/os.h" 5 #include "vm/os.h"
6 #include "vm/thread.h" 6 #include "vm/thread.h"
7 #include "vm/thread_pool.h" 7 #include "vm/thread_pool.h"
8 #include "vm/unit_test.h" 8 #include "vm/unit_test.h"
9 9
10 namespace dart { 10 namespace dart {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 thread_pool.Run(new TestTask(&sync, &done)); 54 thread_pool.Run(new TestTask(&sync, &done));
55 { 55 {
56 MonitorLocker ml(&sync); 56 MonitorLocker ml(&sync);
57 while (!done) { 57 while (!done) {
58 ml.Wait(); 58 ml.Wait();
59 } 59 }
60 } 60 }
61 EXPECT(done); 61 EXPECT(done);
62 62
63 // Do a sanity test on the worker stats. 63 // Do a sanity test on the worker stats.
64 EXPECT_EQ(1, thread_pool.workers_started()); 64 EXPECT_EQ(1U, thread_pool.workers_started());
65 EXPECT_EQ(0, thread_pool.workers_stopped()); 65 EXPECT_EQ(0U, thread_pool.workers_stopped());
66 EXPECT_EQ(1, thread_pool.workers_idle()); 66 EXPECT_EQ(1U, thread_pool.workers_idle());
67 EXPECT_EQ(0, thread_pool.workers_running()); 67 EXPECT_EQ(0U, thread_pool.workers_running());
68 } 68 }
69 69
70 70
71 UNIT_TEST_CASE(ThreadPool_RunMany) { 71 UNIT_TEST_CASE(ThreadPool_RunMany) {
72 const int kTaskCount = 100; 72 const int kTaskCount = 100;
73 ThreadPool thread_pool; 73 ThreadPool thread_pool;
74 Monitor sync[kTaskCount]; 74 Monitor sync[kTaskCount];
75 bool done[kTaskCount]; 75 bool done[kTaskCount];
76 76
77 for (int i = 0; i < kTaskCount; i++) { 77 for (int i = 0; i < kTaskCount; i++) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 EXPECT_EQ(1, exit_count); 126 EXPECT_EQ(1, exit_count);
127 } 127 }
128 128
129 129
130 UNIT_TEST_CASE(ThreadPool_WorkerTimeout) { 130 UNIT_TEST_CASE(ThreadPool_WorkerTimeout) {
131 // Adjust the worker timeout so that we timeout quickly. 131 // Adjust the worker timeout so that we timeout quickly.
132 int saved_timeout = FLAG_worker_timeout_millis; 132 int saved_timeout = FLAG_worker_timeout_millis;
133 FLAG_worker_timeout_millis = 1; 133 FLAG_worker_timeout_millis = 1;
134 134
135 ThreadPool thread_pool; 135 ThreadPool thread_pool;
136 EXPECT_EQ(0, thread_pool.workers_started()); 136 EXPECT_EQ(0U, thread_pool.workers_started());
137 EXPECT_EQ(0, thread_pool.workers_stopped()); 137 EXPECT_EQ(0U, thread_pool.workers_stopped());
138 138
139 // Run a worker. 139 // Run a worker.
140 Monitor sync; 140 Monitor sync;
141 bool done = false; 141 bool done = false;
142 thread_pool.Run(new TestTask(&sync, &done)); 142 thread_pool.Run(new TestTask(&sync, &done));
143 EXPECT_EQ(1, thread_pool.workers_started()); 143 EXPECT_EQ(1U, thread_pool.workers_started());
144 EXPECT_EQ(0, thread_pool.workers_stopped()); 144 EXPECT_EQ(0U, thread_pool.workers_stopped());
145 { 145 {
146 MonitorLocker ml(&sync); 146 MonitorLocker ml(&sync);
147 while (!done) { 147 while (!done) {
148 ml.Wait(); 148 ml.Wait();
149 } 149 }
150 } 150 }
151 EXPECT(done); 151 EXPECT(done);
152 152
153 // Wait up to 5 seconds to see if a worker times out. 153 // Wait up to 5 seconds to see if a worker times out.
154 const int kMaxWait = 5000; 154 const int kMaxWait = 5000;
155 int waited = 0; 155 int waited = 0;
156 while (thread_pool.workers_stopped() == 0 && waited < kMaxWait) { 156 while (thread_pool.workers_stopped() == 0 && waited < kMaxWait) {
157 OS::Sleep(1); 157 OS::Sleep(1);
158 waited += 1; 158 waited += 1;
159 } 159 }
160 EXPECT_EQ(1, thread_pool.workers_stopped()); 160 EXPECT_EQ(1U, thread_pool.workers_stopped());
161 FLAG_worker_timeout_millis = saved_timeout; 161 FLAG_worker_timeout_millis = saved_timeout;
162 } 162 }
163 163
164 164
165 class SpawnTask : public ThreadPool::Task { 165 class SpawnTask : public ThreadPool::Task {
166 public: 166 public:
167 SpawnTask(ThreadPool* pool, Monitor* sync, int todo, int total, int* done) 167 SpawnTask(ThreadPool* pool, Monitor* sync, int todo, int total, int* done)
168 : pool_(pool), sync_(sync), todo_(todo), total_(total), done_(done) { 168 : pool_(pool), sync_(sync), todo_(todo), total_(total), done_(done) {
169 } 169 }
170 170
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 MonitorLocker ml(&sync); 211 MonitorLocker ml(&sync);
212 while (done < kTotalTasks) { 212 while (done < kTotalTasks) {
213 ml.Wait(); 213 ml.Wait();
214 } 214 }
215 } 215 }
216 EXPECT_EQ(kTotalTasks, done); 216 EXPECT_EQ(kTotalTasks, done);
217 } 217 }
218 218
219 219
220 } // namespace dart 220 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698