Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/thread_pool.h" | 5 #include "vm/thread_pool.h" |
| 6 | 6 |
| 7 #include "vm/dart.h" | 7 #include "vm/dart.h" |
| 8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/lockers.h" | 9 #include "vm/lockers.h" |
| 10 | 10 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 current->all_next_ = worker->all_next_; | 205 current->all_next_ = worker->all_next_; |
| 206 worker->all_next_ = NULL; | 206 worker->all_next_ = NULL; |
| 207 worker->owned_ = false; | 207 worker->owned_ = false; |
| 208 return true; | 208 return true; |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 return false; | 211 return false; |
| 212 } | 212 } |
| 213 | 213 |
| 214 | 214 |
| 215 void ThreadPool::SetIdleLocked(Worker* worker) { | |
|
siva
2016/05/16 17:59:27
ASSERT(mutex_.IsOwnedByCurrentThread());
zra
2016/05/16 20:32:55
Done.
| |
| 216 ASSERT(worker->owned_ && !IsIdle(worker)); | |
| 217 worker->idle_next_ = idle_workers_; | |
| 218 idle_workers_ = worker; | |
| 219 count_idle_++; | |
| 220 count_running_--; | |
| 221 } | |
| 222 | |
| 223 | |
| 215 void ThreadPool::SetIdleAndReapExited(Worker* worker) { | 224 void ThreadPool::SetIdleAndReapExited(Worker* worker) { |
| 216 JoinList* list = NULL; | 225 JoinList* list = NULL; |
| 217 { | 226 { |
| 218 MutexLocker ml(&mutex_); | 227 MutexLocker ml(&mutex_); |
| 219 if (shutting_down_) { | 228 if (shutting_down_) { |
| 220 return; | 229 return; |
| 221 } | 230 } |
| 222 ASSERT(worker->owned_ && !IsIdle(worker)); | 231 if (join_list_ == NULL) { |
| 223 worker->idle_next_ = idle_workers_; | 232 // Nothing to join, add to the idle list and return. |
| 224 idle_workers_ = worker; | 233 SetIdleLocked(worker); |
| 225 count_idle_++; | 234 return; |
| 226 count_running_--; | 235 } |
| 227 | 236 // There is something to join. Grab the join list, drop the lock, do the |
| 228 // While we have the lock, opportunistically grab and clear the join_list_. | 237 // join, then grab the lock again and add to the idle list. |
| 229 list = join_list_; | 238 list = join_list_; |
| 230 join_list_ = NULL; | 239 join_list_ = NULL; |
| 231 } | 240 } |
| 232 JoinList::Join(&list); | 241 JoinList::Join(&list); |
| 242 | |
| 243 { | |
| 244 MutexLocker ml(&mutex_); | |
| 245 if (shutting_down_) { | |
| 246 return; | |
| 247 } | |
| 248 SetIdleLocked(worker); | |
| 249 } | |
| 233 } | 250 } |
| 234 | 251 |
| 235 | 252 |
| 236 bool ThreadPool::ReleaseIdleWorker(Worker* worker) { | 253 bool ThreadPool::ReleaseIdleWorker(Worker* worker) { |
| 237 MutexLocker ml(&mutex_); | 254 MutexLocker ml(&mutex_); |
| 238 if (shutting_down_) { | 255 if (shutting_down_) { |
| 239 return false; | 256 return false; |
| 240 } | 257 } |
| 241 // Remove from idle list. | 258 // Remove from idle list. |
| 242 if (!RemoveWorkerFromIdleList(worker)) { | 259 if (!RemoveWorkerFromIdleList(worker)) { |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 } | 503 } |
| 487 | 504 |
| 488 // Call the thread exit hook here to notify the embedder that the | 505 // Call the thread exit hook here to notify the embedder that the |
| 489 // thread pool thread is exiting. | 506 // thread pool thread is exiting. |
| 490 if (Dart::thread_exit_callback() != NULL) { | 507 if (Dart::thread_exit_callback() != NULL) { |
| 491 (*Dart::thread_exit_callback())(); | 508 (*Dart::thread_exit_callback())(); |
| 492 } | 509 } |
| 493 } | 510 } |
| 494 | 511 |
| 495 } // namespace dart | 512 } // namespace dart |
| OLD | NEW |