73c2a13913
This the initial commit for adding a thread pool to the Dart server. For now it is hidden behind a flag (--enable_thread_pool) and when enabled just starts up and processes 100 void tasks. Mac OS implementation is not tested and Windows implementation is still pending. As we are currently not sharing anything between bin/ and vm/ I have just used pthread calls directly in the Linux and Mac OS implementation code. However with Monitor and Thread classes from vm/ the thread pool could be written platform independently. This can always be changed later. R=ager@google.com BUG= TEST= Review URL: http://codereview.chromium.org//8983017 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@2946 260f80e4-7a28-3924-810f-c04153c831b5
45 lines
1.0 KiB
C++
45 lines
1.0 KiB
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::Shutdown() {
|
|
UNIMPLEMENTED();
|
|
}
|
|
|
|
|
|
void ThreadPool::InsertTask(Task task) {
|
|
TaskQueueEntry* entry = new TaskQueueEntry(task);
|
|
queue.Insert(entry);
|
|
}
|
|
|
|
|
|
Task ThreadPool::WaitForTask() {
|
|
TaskQueueEntry* entry = queue.Remove();
|
|
if (entry == NULL) {
|
|
return -1;
|
|
}
|
|
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 (true) {
|
|
if (Dart_IsVMFlagSet("trace_thread_pool")) {
|
|
printf("Waiting for task\n");
|
|
}
|
|
Task task = pool->WaitForTask();
|
|
if (Dart_IsVMFlagSet("trace_thread_pool")) {
|
|
printf("Got task %d\n", task);
|
|
}
|
|
}
|
|
return NULL;
|
|
};
|