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

Side by Side 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: Rebased to r3454 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "bin/thread.h" 7 #include "bin/thread.h"
8 8
9 void TaskQueue::Insert(TaskQueueEntry* entry) { 9 void TaskQueue::Insert(TaskQueueEntry* entry) {
10 MonitorLocker monitor(&monitor_); 10 MonitorLocker monitor(&monitor_);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 TaskQueueEntry* entry = queue_.Remove(); 56 TaskQueueEntry* entry = queue_.Remove();
57 if (entry == NULL) { 57 if (entry == NULL) {
58 return NULL; 58 return NULL;
59 } 59 }
60 Task task = entry->task(); 60 Task task = entry->task();
61 delete entry; 61 delete entry;
62 return task; 62 return task;
63 } 63 }
64 64
65 65
66 void* ThreadPool::Main(void* args) { 66 void ThreadPool::Start() {
67 threads_
68 = reinterpret_cast<dart::ThreadHandle*>(
69 calloc(size_, sizeof(dart::ThreadHandle)));
Mads Ager (google) 2012/01/20 12:35:34 I think we usually use 4-space indent we we have t
Søren Gjesse 2012/01/20 13:25:45 Done.
70 for (int i = 0; i < size_; i++) {
71 threads_[i] = dart::Thread::Start(&ThreadPool::Main,
72 reinterpret_cast<uword>(this));
73 if (threads_[i] == dart::Thread::kInvalidThreadHandle) {
74 FATAL("Create and start thread pool thread");
75 }
76 }
77 }
78
79
80 void ThreadPool::Shutdown() {
81 terminate_ = true;
82 queue_.Shutdown();
83 for (int i = 0; i < size_; i++) {
84 dart::Thread::Join(threads_[i]);
85 }
86 }
87
88
89 void ThreadPool::Main(uword args) {
67 if (Dart_IsVMFlagSet("trace_thread_pool")) { 90 if (Dart_IsVMFlagSet("trace_thread_pool")) {
68 printf("Thread pool thread started\n"); 91 printf("Thread pool thread started\n");
69 } 92 }
70 ThreadPool* pool = reinterpret_cast<ThreadPool*>(args); 93 ThreadPool* pool = reinterpret_cast<ThreadPool*>(args);
71 while (!pool->terminate_) { 94 while (!pool->terminate_) {
72 if (Dart_IsVMFlagSet("trace_thread_pool")) { 95 if (Dart_IsVMFlagSet("trace_thread_pool")) {
73 printf("Waiting for task\n"); 96 printf("Waiting for task\n");
74 } 97 }
75 Task task = pool->WaitForTask(); 98 Task task = pool->WaitForTask();
76 if (pool->terminate_) return NULL; 99 if (pool->terminate_) return;
77 (*(pool->task_handler_))(task); 100 (*(pool->task_handler_))(task);
78 } 101 }
79 return NULL;
80 }; 102 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698