MCPcopy Create free account
hub / github.com/apache/thrift / removeWorkersUnderLock

Method removeWorkersUnderLock

lib/cpp/src/thrift/concurrency/ThreadManager.cpp:411–446  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

409}
410
411void 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
448bool ThreadManager::Impl::canSleep() const {
449 const Thread::id_t id = threadFactory_->getCurrentThreadId();

Callers

nothing calls this directly

Calls 8

isDetachedMethod · 0.80
clearMethod · 0.65
notifyMethod · 0.45
notifyAllMethod · 0.45
waitMethod · 0.45
joinMethod · 0.45
getIdMethod · 0.45

Tested by

no test coverage detected