Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Unified Diff: runtime/bin/thread_pool.cc

Issue 9141005: Change the thread interface in runtime/platform and use it starting all threads (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from ager@ Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/bin/thread_pool.cc
diff --git a/runtime/bin/thread_pool.cc b/runtime/bin/thread_pool.cc
index 36960a72303b798454eb01b72b3cfa802a1044ce..c01204af2d22466149559ac8c2aa513d7b0dc2dc 100644
--- a/runtime/bin/thread_pool.cc
+++ b/runtime/bin/thread_pool.cc
@@ -63,7 +63,29 @@ Task ThreadPool::WaitForTask() {
}
-void* ThreadPool::Main(void* args) {
+void ThreadPool::Start() {
+ threads_ = reinterpret_cast<dart::ThreadHandle*>(calloc(
+ size_, sizeof(dart::ThreadHandle)));
+ for (int i = 0; i < size_; i++) {
+ threads_[i] = dart::Thread::Start(&ThreadPool::Main,
+ reinterpret_cast<uword>(this));
+ if (threads_[i] == dart::Thread::kInvalidThreadHandle) {
+ FATAL("Create and start thread pool thread");
+ }
+ }
+}
+
+
+void ThreadPool::Shutdown() {
+ terminate_ = true;
+ queue_.Shutdown();
+ for (int i = 0; i < size_; i++) {
+ dart::Thread::Join(threads_[i]);
Ivan Posva 2012/01/20 16:45:55 This will not work, please see comment in thread.h
Søren Gjesse 2012/01/23 13:14:58 See reply in thread.h
+ }
+}
+
+
+void ThreadPool::Main(uword args) {
if (Dart_IsVMFlagSet("trace_thread_pool")) {
printf("Thread pool thread started\n");
}
@@ -73,8 +95,7 @@ void* ThreadPool::Main(void* args) {
printf("Waiting for task\n");
}
Task task = pool->WaitForTask();
- if (pool->terminate_) return NULL;
+ if (pool->terminate_) return;
(*(pool->task_handler_))(task);
}
- return NULL;
};

Powered by Google App Engine
This is Rietveld 408576698