| Index: runtime/vm/thread_pool.h
|
| diff --git a/runtime/vm/thread_pool.h b/runtime/vm/thread_pool.h
|
| index 792aef7b23898d4cda77cf6345f11b6dfe0ff770..7c030eccb60c182fed3b95e4bed25bd888000394 100644
|
| --- a/runtime/vm/thread_pool.h
|
| +++ b/runtime/vm/thread_pool.h
|
| @@ -5,11 +5,14 @@
|
| #ifndef VM_THREAD_POOL_H_
|
| #define VM_THREAD_POOL_H_
|
|
|
| +#include "vm/allocation.h"
|
| #include "vm/globals.h"
|
| #include "vm/os_thread.h"
|
|
|
| namespace dart {
|
|
|
| +class ReaperTask;
|
| +
|
| class ThreadPool {
|
| public:
|
| // Subclasses of Task are able to run on a ThreadPool.
|
| @@ -29,7 +32,7 @@ class ThreadPool {
|
|
|
| ThreadPool();
|
|
|
| - // Shuts down this thread pool. Causes workers to terminate
|
| + // Shuts down this thread pool. Causes workers to terminate
|
| // themselves when they are active again.
|
| ~ThreadPool();
|
|
|
| @@ -43,7 +46,7 @@ class ThreadPool {
|
| uint64_t workers_stopped() const { return count_stopped_; }
|
|
|
| private:
|
| - friend class ThreadPoolTestPeer;
|
| + friend class ReaperTask;
|
|
|
| class Worker {
|
| public:
|
| @@ -56,24 +59,31 @@ class ThreadPool {
|
| // 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();
|
|
|
| + // Get the Worker's thread id.
|
| + ThreadId id() { return id_; }
|
| +
|
| private:
|
| friend class ThreadPool;
|
|
|
| // The main entry point for new worker threads.
|
| static void Main(uword args);
|
|
|
| - bool IsDone() const { return pool_ == NULL; }
|
| + bool IsDone() const { return done_; }
|
|
|
| // Fields owned by Worker.
|
| Monitor monitor_;
|
| ThreadPool* pool_;
|
| Task* task_;
|
| + ThreadJoinId id_;
|
| + bool started_;
|
| + bool done_;
|
|
|
| // Fields owned by ThreadPool. Workers should not look at these
|
| // directly. It's like looking at the sun.
|
| @@ -81,9 +91,30 @@ class ThreadPool {
|
| 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);
|
| };
|
|
|
| + class JoinList {
|
| + public:
|
| + explicit JoinList(ThreadJoinId id, JoinList* next) : id_(id), next_(next) {
|
| + }
|
| +
|
| + static void Add(ThreadJoinId id, JoinList** list);
|
| +
|
| + static void Join(JoinList** list);
|
| +
|
| + ThreadJoinId id() const { return id_; }
|
| + JoinList* next() const { return next_; }
|
| +
|
| + private:
|
| + ThreadJoinId id_;
|
| + JoinList* next_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(JoinList);
|
| + };
|
| +
|
| void Shutdown();
|
|
|
| // Expensive. Use only in assertions.
|
| @@ -92,6 +123,11 @@ class ThreadPool {
|
| bool RemoveWorkerFromIdleList(Worker* worker);
|
| bool RemoveWorkerFromAllList(Worker* worker);
|
|
|
| + void AddWorkerToShutdownList(Worker* worker);
|
| + bool RemoveWorkerFromShutdownList(Worker* worker);
|
| +
|
| + void ReapExitedIdleThreads();
|
| +
|
| // Worker operations.
|
| void SetIdle(Worker* worker);
|
| bool ReleaseIdleWorker(Worker* worker);
|
| @@ -104,9 +140,11 @@ class ThreadPool {
|
| uint64_t count_stopped_;
|
| uint64_t count_running_;
|
| uint64_t count_idle_;
|
| + JoinList* idle_join_list_;
|
|
|
| - static Monitor* exit_monitor_; // Used only in testing.
|
| - static int* exit_count_; // Used only in testing.
|
| + Monitor exit_monitor_;
|
| + Worker* shutting_down_workers_;
|
| + JoinList* join_list_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ThreadPool);
|
| };
|
|
|