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

Unified Diff: runtime/vm/thread_pool.h

Issue 850183003: During thread-pool shutdown, wait for worker threads to shutdown. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 6 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/vm/dart.cc ('k') | runtime/vm/thread_pool.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/thread_pool.h
===================================================================
--- runtime/vm/thread_pool.h (revision 45833)
+++ runtime/vm/thread_pool.h (working copy)
@@ -43,8 +43,6 @@
uint64_t workers_stopped() const { return count_stopped_; }
private:
- friend class ThreadPoolTestPeer;
-
class Worker {
public:
explicit Worker(ThreadPool* pool);
@@ -56,12 +54,16 @@
// after a task has been set by the initial call to SetTask().
void StartThread();
- // Main loop for a worker.
- void Loop();
+ // Main loop for a worker. Returns true if worker is removed from thread
+ // lists, false otherwise.
+ bool Loop();
// Causes worker to terminate eventually.
- void Shutdown();
+ bool Shutdown();
+ // Get the Worker's thread id.
+ ThreadId id() { return id_; }
+
private:
friend class ThreadPool;
@@ -74,6 +76,8 @@
Monitor monitor_;
ThreadPool* pool_;
Task* task_;
+ ThreadId id_;
+ bool started_;
// Fields owned by ThreadPool. Workers should not look at these
// directly. It's like looking at the sun.
@@ -80,6 +84,7 @@
bool owned_; // Protected by ThreadPool::mutex_
Worker* all_next_; // Protected by ThreadPool::mutex_
Worker* idle_next_; // Protected by ThreadPool::mutex_
+ Worker* shutdown_next_; // Protected by ThreadPool::exit_monitor
DISALLOW_COPY_AND_ASSIGN(Worker);
};
@@ -92,6 +97,9 @@
bool RemoveWorkerFromIdleList(Worker* worker);
bool RemoveWorkerFromAllList(Worker* worker);
+ static void AddWorkerToShutdownList(Worker* worker);
+ static bool RemoveWorkerFromShutdownList(Worker* worker);
+
// Worker operations.
void SetIdle(Worker* worker);
bool ReleaseIdleWorker(Worker* worker);
@@ -105,8 +113,8 @@
uint64_t count_running_;
uint64_t count_idle_;
- static Monitor* exit_monitor_; // Used only in testing.
- static int* exit_count_; // Used only in testing.
+ static Monitor exit_monitor_;
+ static Worker* shutting_down_workers_;
DISALLOW_COPY_AND_ASSIGN(ThreadPool);
};
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/thread_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698