| 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 "bin/thread_pool.h" | 5 #include "bin/thread_pool.h" |
| 6 | 6 |
| 7 void ThreadPool::Shutdown() { | |
| 8 UNIMPLEMENTED(); | |
| 9 } | |
| 10 | |
| 11 | |
| 12 void ThreadPool::InsertTask(Task task) { | 7 void ThreadPool::InsertTask(Task task) { |
| 13 TaskQueueEntry* entry = new TaskQueueEntry(task); | 8 TaskQueueEntry* entry = new TaskQueueEntry(task); |
| 14 queue.Insert(entry); | 9 queue_.Insert(entry); |
| 15 } | 10 } |
| 16 | 11 |
| 17 | 12 |
| 18 Task ThreadPool::WaitForTask() { | 13 Task ThreadPool::WaitForTask() { |
| 19 TaskQueueEntry* entry = queue.Remove(); | 14 TaskQueueEntry* entry = queue_.Remove(); |
| 20 if (entry == NULL) { | 15 if (entry == NULL) { |
| 21 return -1; | 16 return NULL; |
| 22 } | 17 } |
| 23 Task task = entry->task(); | 18 Task task = entry->task(); |
| 24 delete entry; | 19 delete entry; |
| 25 return task; | 20 return task; |
| 26 } | 21 } |
| 27 | 22 |
| 28 | 23 |
| 29 void* ThreadPool::Main(void* args) { | 24 void* ThreadPool::Main(void* args) { |
| 30 if (Dart_IsVMFlagSet("trace_thread_pool")) { | 25 if (Dart_IsVMFlagSet("trace_thread_pool")) { |
| 31 printf("Thread pool thread started\n"); | 26 printf("Thread pool thread started\n"); |
| 32 } | 27 } |
| 33 ThreadPool* pool = reinterpret_cast<ThreadPool*>(args); | 28 ThreadPool* pool = reinterpret_cast<ThreadPool*>(args); |
| 34 while (true) { | 29 while (!pool->terminate_) { |
| 35 if (Dart_IsVMFlagSet("trace_thread_pool")) { | 30 if (Dart_IsVMFlagSet("trace_thread_pool")) { |
| 36 printf("Waiting for task\n"); | 31 printf("Waiting for task\n"); |
| 37 } | 32 } |
| 38 Task task = pool->WaitForTask(); | 33 Task task = pool->WaitForTask(); |
| 39 if (Dart_IsVMFlagSet("trace_thread_pool")) { | 34 if (pool->terminate_) return NULL; |
| 40 printf("Got task %d\n", task); | 35 (*(pool->task_handler_))(task); |
| 41 } | |
| 42 } | 36 } |
| 43 return NULL; | 37 return NULL; |
| 44 }; | 38 }; |
| OLD | NEW |