| 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);
|
| };
|
|
|