Files
sdk/runtime/bin/thread_pool.cc
T
sgjesse@google.com a6071e0880 Thread pool changes
Make one global thread pool instead of a thread pool for each
eventhandler (i.e. isolate).

Also:

* Added handler function for thread pool tasks.
* Added thread pool shutdown.
* Added a simple test.

R=ager@google.com

BUG=
TEST=

Review URL: http://codereview.chromium.org//9112013

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3079 260f80e4-7a28-3924-810f-c04153c831b5
2012-01-09 07:38:30 +00:00

39 lines
997 B
C++

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "bin/thread_pool.h"
void ThreadPool::InsertTask(Task task) {
TaskQueueEntry* entry = new TaskQueueEntry(task);
queue_.Insert(entry);
}
Task ThreadPool::WaitForTask() {
TaskQueueEntry* entry = queue_.Remove();
if (entry == NULL) {
return NULL;
}
Task task = entry->task();
delete entry;
return task;
}
void* ThreadPool::Main(void* args) {
if (Dart_IsVMFlagSet("trace_thread_pool")) {
printf("Thread pool thread started\n");
}
ThreadPool* pool = reinterpret_cast<ThreadPool*>(args);
while (!pool->terminate_) {
if (Dart_IsVMFlagSet("trace_thread_pool")) {
printf("Waiting for task\n");
}
Task task = pool->WaitForTask();
if (pool->terminate_) return NULL;
(*(pool->task_handler_))(task);
}
return NULL;
};