Chromium Code Reviews| Index: runtime/bin/thread_pool.cc |
| diff --git a/runtime/bin/thread_pool.cc b/runtime/bin/thread_pool.cc |
| index 36960a72303b798454eb01b72b3cfa802a1044ce..90cd9d30604588d8c30e21aeb103d1699424f0ac 100644 |
| --- a/runtime/bin/thread_pool.cc |
| +++ b/runtime/bin/thread_pool.cc |
| @@ -63,7 +63,33 @@ Task ThreadPool::WaitForTask() { |
| } |
| -void* ThreadPool::Main(void* args) { |
| +void ThreadPool::Start() { |
| + MonitorLocker monitor(&monitor_); |
| + for (int i = 0; i < size_; i++) { |
| + dart::Thread::Start(&ThreadPool::Main, |
| + reinterpret_cast<uword>(this)); |
|
siva
2012/01/24 02:26:05
If you choose to have an error return value for Th
Søren Gjesse
2012/01/24 12:07:55
Added return code to Thread::Start. For now just a
|
| + } |
| +} |
| + |
| + |
| +void ThreadPool::Shutdown() { |
| + terminate_ = true; |
|
Ivan Posva
2012/01/24 02:04:01
Please do not access shared state outside the lock
Søren Gjesse
2012/01/24 12:07:55
Agree, moved thread_pool cleanup to separate CL, h
|
| + queue_.Shutdown(); |
| + MonitorLocker monitor(&monitor_); |
|
Ivan Posva
2012/01/24 02:04:01
The TaskQueue should be an implementation detail o
Søren Gjesse
2012/01/24 12:07:55
Agree, moved thread_pool cleanup to separate CL, h
|
| + while (size_ > 0) { |
| + monitor.Wait(); |
| + } |
| +} |
| + |
| + |
| +void ThreadPool::ThreadTerminated() { |
| + MonitorLocker monitor(&monitor_); |
| + size_--; |
| + monitor.Notify(); |
| +} |
| + |
| + |
| +void ThreadPool::Main(uword args) { |
| if (Dart_IsVMFlagSet("trace_thread_pool")) { |
| printf("Thread pool thread started\n"); |
| } |
| @@ -73,8 +99,8 @@ void* ThreadPool::Main(void* args) { |
| printf("Waiting for task\n"); |
| } |
| Task task = pool->WaitForTask(); |
| - if (pool->terminate_) return NULL; |
| + if (pool->terminate_) continue; |
|
siva
2012/01/24 02:26:05
Why continue and not a break?
Søren Gjesse
2012/01/24 12:07:55
No particular reason, changed to break.
|
| (*(pool->task_handler_))(task); |
| } |
| - return NULL; |
| + pool->ThreadTerminated(); |
| }; |