Chromium Code Reviews| Index: runtime/vm/thread_pool.cc |
| diff --git a/runtime/vm/thread_pool.cc b/runtime/vm/thread_pool.cc |
| index fb0f7d7c69b2fac5d7d1af0843eaa2e08c87500f..cd39a59afe26177f14dedc7f923d1b49bc434ef0 100644 |
| --- a/runtime/vm/thread_pool.cc |
| +++ b/runtime/vm/thread_pool.cc |
| @@ -212,6 +212,15 @@ bool ThreadPool::RemoveWorkerFromAllList(Worker* worker) { |
| } |
| +void ThreadPool::SetIdleLocked(Worker* worker) { |
|
siva
2016/05/16 17:59:27
ASSERT(mutex_.IsOwnedByCurrentThread());
zra
2016/05/16 20:32:55
Done.
|
| + ASSERT(worker->owned_ && !IsIdle(worker)); |
| + worker->idle_next_ = idle_workers_; |
| + idle_workers_ = worker; |
| + count_idle_++; |
| + count_running_--; |
| +} |
| + |
| + |
| void ThreadPool::SetIdleAndReapExited(Worker* worker) { |
| JoinList* list = NULL; |
| { |
| @@ -219,17 +228,25 @@ void ThreadPool::SetIdleAndReapExited(Worker* worker) { |
| if (shutting_down_) { |
| return; |
| } |
| - ASSERT(worker->owned_ && !IsIdle(worker)); |
| - worker->idle_next_ = idle_workers_; |
| - idle_workers_ = worker; |
| - count_idle_++; |
| - count_running_--; |
| - |
| - // While we have the lock, opportunistically grab and clear the join_list_. |
| + if (join_list_ == NULL) { |
| + // Nothing to join, add to the idle list and return. |
| + SetIdleLocked(worker); |
| + return; |
| + } |
| + // There is something to join. Grab the join list, drop the lock, do the |
| + // join, then grab the lock again and add to the idle list. |
| list = join_list_; |
| join_list_ = NULL; |
| } |
| JoinList::Join(&list); |
| + |
| + { |
| + MutexLocker ml(&mutex_); |
| + if (shutting_down_) { |
| + return; |
| + } |
| + SetIdleLocked(worker); |
| + } |
| } |