OLD | NEW |
---|---|
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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
326 | 326 |
327 | 327 |
328 void ThreadPool::Worker::StartThread() { | 328 void ThreadPool::Worker::StartThread() { |
329 #if defined(DEBUG) | 329 #if defined(DEBUG) |
330 // Must call SetTask before StartThread. | 330 // Must call SetTask before StartThread. |
331 { // NOLINT | 331 { // NOLINT |
332 MonitorLocker ml(&monitor_); | 332 MonitorLocker ml(&monitor_); |
333 ASSERT(task_ != NULL); | 333 ASSERT(task_ != NULL); |
334 } | 334 } |
335 #endif | 335 #endif |
336 int result = OSThread::Start(&Worker::Main, reinterpret_cast<uword>(this)); | 336 int result = OSThread::Start("Dart ThreadPool Worker", |
337 &Worker::Main, | |
338 reinterpret_cast<uword>(this)); | |
337 if (result != 0) { | 339 if (result != 0) { |
338 FATAL1("Could not start worker thread: result = %d.", result); | 340 FATAL1("Could not start worker thread: result = %d.", result); |
339 } | 341 } |
340 } | 342 } |
341 | 343 |
342 | 344 |
343 void ThreadPool::Worker::SetTask(Task* task) { | 345 void ThreadPool::Worker::SetTask(Task* task) { |
344 MonitorLocker ml(&monitor_); | 346 MonitorLocker ml(&monitor_); |
345 ASSERT(task_ == NULL); | 347 ASSERT(task_ == NULL); |
346 task_ = task; | 348 task_ = task; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
410 | 412 |
411 void ThreadPool::Worker::Shutdown() { | 413 void ThreadPool::Worker::Shutdown() { |
412 MonitorLocker ml(&monitor_); | 414 MonitorLocker ml(&monitor_); |
413 done_ = true; | 415 done_ = true; |
414 ml.Notify(); | 416 ml.Notify(); |
415 } | 417 } |
416 | 418 |
417 | 419 |
418 // static | 420 // static |
419 void ThreadPool::Worker::Main(uword args) { | 421 void ThreadPool::Worker::Main(uword args) { |
420 Thread::EnsureInit(); | |
421 Thread* thread = Thread::Current(); | |
422 thread->set_name("Dart ThreadPool Worker"); | |
423 Worker* worker = reinterpret_cast<Worker*>(args); | 422 Worker* worker = reinterpret_cast<Worker*>(args); |
424 ThreadId id = OSThread::GetCurrentThreadId(); | 423 ThreadId id = OSThread::GetCurrentThreadId(); |
425 ThreadJoinId join_id = OSThread::GetCurrentThreadJoinId(); | 424 ThreadJoinId join_id = OSThread::GetCurrentThreadJoinId(); |
zra
2015/11/16 20:12:28
In the future on Windows we might want to ensure t
siva
2015/11/17 20:52:25
Changed this to os_thread->Id() and os_thread->Joi
| |
426 ThreadPool* pool; | 425 ThreadPool* pool; |
427 | 426 |
428 { | 427 { |
429 MonitorLocker ml(&worker->monitor_); | 428 MonitorLocker ml(&worker->monitor_); |
430 ASSERT(worker->task_); | 429 ASSERT(worker->task_); |
431 worker->id_ = id; | 430 worker->id_ = id; |
432 pool = worker->pool_; | 431 pool = worker->pool_; |
433 } | 432 } |
434 | 433 |
435 bool released = worker->Loop(); | 434 bool released = worker->Loop(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 // is not due to a ThreadPool Shutdown. Thus, we simply delete the worker. | 468 // is not due to a ThreadPool Shutdown. Thus, we simply delete the worker. |
470 // The worker's id is added to the thread pool's join list by | 469 // The worker's id is added to the thread pool's join list by |
471 // ReleaseIdleWorker, so in the case that the thread pool begins shutting | 470 // ReleaseIdleWorker, so in the case that the thread pool begins shutting |
472 // down immediately after returning from worker->Loop() above, we still | 471 // down immediately after returning from worker->Loop() above, we still |
473 // wait for the thread to exit by joining on it in Shutdown(). | 472 // wait for the thread to exit by joining on it in Shutdown(). |
474 delete worker; | 473 delete worker; |
475 } | 474 } |
476 } | 475 } |
477 | 476 |
478 } // namespace dart | 477 } // namespace dart |
OLD | NEW |