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..cf1ec3b9d4cc941322d0857bc81f98f987613489 100644 |
| --- a/runtime/bin/thread_pool.cc |
| +++ b/runtime/bin/thread_pool.cc |
| @@ -63,7 +63,36 @@ Task ThreadPool::WaitForTask() { |
| } |
| -void* ThreadPool::Main(void* args) { |
| +void ThreadPool::Start() { |
| + MonitorLocker monitor(&monitor_); |
|
Ivan Posva
2012/02/02 07:53:24
It is very, very confusing to have two different M
Søren Gjesse
2012/02/02 08:46:08
They are in different namespaces though. I will tr
|
| + for (int i = 0; i < size_; i++) { |
| + int result = dart::Thread::Start(&ThreadPool::Main, |
| + reinterpret_cast<uword>(this)); |
| + if (result != 0) { |
| + FATAL1("Failed to start thread pool thread %d", result); |
| + } |
| + } |
| +} |
| + |
| + |
| +void ThreadPool::Shutdown() { |
| + terminate_ = true; |
| + queue_.Shutdown(); |
| + MonitorLocker monitor(&monitor_); |
| + 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 +102,8 @@ void* ThreadPool::Main(void* args) { |
| printf("Waiting for task\n"); |
| } |
| Task task = pool->WaitForTask(); |
| - if (pool->terminate_) return NULL; |
| + if (pool->terminate_) break; |
| (*(pool->task_handler_))(task); |
| } |
| - return NULL; |
| + pool->ThreadTerminated(); |
| }; |