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

Unified Diff: runtime/bin/thread_pool.cc

Issue 9231020: Use platform implementation of Monitor in thread pool (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
« no previous file with comments | « runtime/bin/thread_pool.h ('k') | runtime/bin/thread_pool_linux.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/thread_pool.cc
diff --git a/runtime/bin/thread_pool.cc b/runtime/bin/thread_pool.cc
index f8c26e87e010ee24712a271722ab554068ed3cca..d93b8f844aa24e5423a2d55032ac1216e9354925 100644
--- a/runtime/bin/thread_pool.cc
+++ b/runtime/bin/thread_pool.cc
@@ -4,6 +4,50 @@
#include "bin/thread_pool.h"
+void TaskQueue::Insert(TaskQueueEntry* entry) {
+ monitor_.Enter();
+ if (head_ == NULL) {
+ head_ = entry;
+ tail_ = entry;
+ monitor_.Notify();
+ } else {
+ tail_->set_next(entry);
+ tail_ = entry;
+ }
+ monitor_.Exit();
+}
+
+
+TaskQueueEntry* TaskQueue::Remove() {
+ monitor_.Enter();
+ TaskQueueEntry* result = head_;
+ while (result == NULL) {
+ if (terminate_) {
+ monitor_.Exit();
+ return NULL;
+ }
+ monitor_.Wait(dart::Monitor::kNoTimeout);
+ if (terminate_) {
+ monitor_.Exit();
+ return NULL;
+ }
+ result = head_;
+ }
+ head_ = result->next();
+ ASSERT(head_ != NULL || tail_ == result);
+ monitor_.Exit();
+ return result;
+}
+
+
+void TaskQueue::Shutdown() {
+ monitor_.Enter();
+ terminate_ = true;
+ monitor_.NotifyAll();
+ monitor_.Exit();
+}
+
+
void ThreadPool::InsertTask(Task task) {
TaskQueueEntry* entry = new TaskQueueEntry(task);
queue_.Insert(entry);
« no previous file with comments | « runtime/bin/thread_pool.h ('k') | runtime/bin/thread_pool_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698