| 409 | } |
| 410 | |
| 411 | void ThreadManager::Impl::removeWorkersUnderLock(size_t value) { |
| 412 | if (value > workerMaxCount_) { |
| 413 | throw InvalidArgumentException(); |
| 414 | } |
| 415 | |
| 416 | workerMaxCount_ -= value; |
| 417 | |
| 418 | if (idleCount_ > value) { |
| 419 | // There are more idle workers than we need to remove, |
| 420 | // so notify enough of them so they can terminate. |
| 421 | for (size_t ix = 0; ix < value; ix++) { |
| 422 | monitor_.notify(); |
| 423 | } |
| 424 | } else { |
| 425 | // There are as many or less idle workers than we need to remove, |
| 426 | // so just notify them all so they can terminate. |
| 427 | monitor_.notifyAll(); |
| 428 | } |
| 429 | |
| 430 | while (workerCount_ != workerMaxCount_) { |
| 431 | workerMonitor_.wait(); |
| 432 | } |
| 433 | |
| 434 | for (const auto & deadWorker : deadWorkers_) { |
| 435 | |
| 436 | // when used with a joinable thread factory, we join the threads as we remove them |
| 437 | if (!threadFactory_->isDetached()) { |
| 438 | deadWorker->join(); |
| 439 | } |
| 440 | |
| 441 | idMap_.erase(deadWorker->getId()); |
| 442 | workers_.erase(deadWorker); |
| 443 | } |
| 444 | |
| 445 | deadWorkers_.clear(); |
| 446 | } |
| 447 | |
| 448 | bool ThreadManager::Impl::canSleep() const { |
| 449 | const Thread::id_t id = threadFactory_->getCurrentThreadId(); |
nothing calls this directly
no test coverage detected