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

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

Issue 1134003005: Automatic thread cleanup on non-Windows platforms. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/thread.cc ('k') | 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/thread_pool.h" 5 #include "vm/thread_pool.h"
6 6
7 #include "vm/flags.h" 7 #include "vm/flags.h"
8 #include "vm/lockers.h" 8 #include "vm/lockers.h"
9 9
10 namespace dart { 10 namespace dart {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 void ThreadPool::Worker::Loop() { 267 void ThreadPool::Worker::Loop() {
268 MonitorLocker ml(&monitor_); 268 MonitorLocker ml(&monitor_);
269 int64_t idle_start; 269 int64_t idle_start;
270 while (true) { 270 while (true) {
271 ASSERT(task_ != NULL); 271 ASSERT(task_ != NULL);
272 Task* task = task_; 272 Task* task = task_;
273 task_ = NULL; 273 task_ = NULL;
274 274
275 // Release monitor while handling the task. 275 // Release monitor while handling the task.
276 monitor_.Exit(); 276 monitor_.Exit();
277 Thread::EnsureInit();
278 task->Run(); 277 task->Run();
279 ASSERT(Isolate::Current() == NULL); 278 ASSERT(Isolate::Current() == NULL);
280 // Prevent unintended sharing of state between tasks.
281 Thread::CleanUp();
282 delete task; 279 delete task;
283 monitor_.Enter(); 280 monitor_.Enter();
284 281
285 ASSERT(task_ == NULL); 282 ASSERT(task_ == NULL);
286 if (IsDone()) { 283 if (IsDone()) {
287 return; 284 return;
288 } 285 }
289 ASSERT(pool_ != NULL); 286 ASSERT(pool_ != NULL);
290 pool_->SetIdle(this); 287 pool_->SetIdle(this);
291 idle_start = OS::GetCurrentTimeMillis(); 288 idle_start = OS::GetCurrentTimeMillis();
(...skipping 19 matching lines...) Expand all
311 308
312 void ThreadPool::Worker::Shutdown() { 309 void ThreadPool::Worker::Shutdown() {
313 MonitorLocker ml(&monitor_); 310 MonitorLocker ml(&monitor_);
314 pool_ = NULL; // Fail fast if someone tries to access pool_. 311 pool_ = NULL; // Fail fast if someone tries to access pool_.
315 ml.Notify(); 312 ml.Notify();
316 } 313 }
317 314
318 315
319 // static 316 // static
320 void ThreadPool::Worker::Main(uword args) { 317 void ThreadPool::Worker::Main(uword args) {
318 Thread::EnsureInit();
321 Worker* worker = reinterpret_cast<Worker*>(args); 319 Worker* worker = reinterpret_cast<Worker*>(args);
322 worker->Loop(); 320 worker->Loop();
323 321
324 // It should be okay to access these unlocked here in this assert. 322 // It should be okay to access these unlocked here in this assert.
325 ASSERT(!worker->owned_ && 323 ASSERT(!worker->owned_ &&
326 worker->all_next_ == NULL && 324 worker->all_next_ == NULL &&
327 worker->idle_next_ == NULL); 325 worker->idle_next_ == NULL);
328 326
329 // The exit monitor is only used during testing. 327 // The exit monitor is only used during testing.
330 if (ThreadPool::exit_monitor_) { 328 if (ThreadPool::exit_monitor_) {
331 MonitorLocker ml(ThreadPool::exit_monitor_); 329 MonitorLocker ml(ThreadPool::exit_monitor_);
332 (*ThreadPool::exit_count_)++; 330 (*ThreadPool::exit_count_)++;
333 ml.Notify(); 331 ml.Notify();
334 } 332 }
335 delete worker; 333 delete worker;
334 #if defined(TARGET_OS_WINDOWS)
335 Thread::CleanUp();
336 #endif
336 } 337 }
337 338
338 } // namespace dart 339 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698