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

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: Removed Thread::Join as suggested by iposva@ 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 MonitorLocker monitor(&monitor_);
68 for (int i = 0; i < size_; i++) {
69 dart::Thread::Start(&ThreadPool::Main,
70 reinterpret_cast<uword>(this));
siva 2012/01/24 02:26:05 If you choose to have an error return value for Th
Søren Gjesse 2012/01/24 12:07:55 Added return code to Thread::Start. For now just a
71 }
72 }
73
74
75 void ThreadPool::Shutdown() {
76 terminate_ = true;
Ivan Posva 2012/01/24 02:04:01 Please do not access shared state outside the lock
Søren Gjesse 2012/01/24 12:07:55 Agree, moved thread_pool cleanup to separate CL, h
77 queue_.Shutdown();
78 MonitorLocker monitor(&monitor_);
Ivan Posva 2012/01/24 02:04:01 The TaskQueue should be an implementation detail o
Søren Gjesse 2012/01/24 12:07:55 Agree, moved thread_pool cleanup to separate CL, h
79 while (size_ > 0) {
80 monitor.Wait();
81 }
82 }
83
84
85 void ThreadPool::ThreadTerminated() {
86 MonitorLocker monitor(&monitor_);
87 size_--;
88 monitor.Notify();
89 }
90
91
92 void ThreadPool::Main(uword args) {
67 if (Dart_IsVMFlagSet("trace_thread_pool")) { 93 if (Dart_IsVMFlagSet("trace_thread_pool")) {
68 printf("Thread pool thread started\n"); 94 printf("Thread pool thread started\n");
69 } 95 }
70 ThreadPool* pool = reinterpret_cast<ThreadPool*>(args); 96 ThreadPool* pool = reinterpret_cast<ThreadPool*>(args);
71 while (!pool->terminate_) { 97 while (!pool->terminate_) {
72 if (Dart_IsVMFlagSet("trace_thread_pool")) { 98 if (Dart_IsVMFlagSet("trace_thread_pool")) {
73 printf("Waiting for task\n"); 99 printf("Waiting for task\n");
74 } 100 }
75 Task task = pool->WaitForTask(); 101 Task task = pool->WaitForTask();
76 if (pool->terminate_) return NULL; 102 if (pool->terminate_) continue;
siva 2012/01/24 02:26:05 Why continue and not a break?
Søren Gjesse 2012/01/24 12:07:55 No particular reason, changed to break.
77 (*(pool->task_handler_))(task); 103 (*(pool->task_handler_))(task);
78 } 104 }
79 return NULL; 105 pool->ThreadTerminated();
80 }; 106 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698