void CPUThreadPoolExecutor::threadRun(ThreadPtr thread) { this->threadPoolHook_.registerThread(); thread->startupBaton.post(); while (true) { auto task = taskQueue_->try_take_for(threadTimeout_); // Handle thread stopping, either by task timeout, or // by 'poison' task added in join() or stop(). if (UNLIKELY(!task || task.value().poison)) { // Actually remove the thread from the list. SharedMutex::WriteHolder w{&threadListLock_}; if (taskShouldStop(task)) { for (auto& o : observers_) { o->threadStopped(thread.get()); } threadList_.remove(thread); stoppedThreads_.add(thread); return; } else { continue; } } runTask(thread, std::move(task.value())); if (UNLIKELY(threadsToStop_ > 0 && !isJoin_)) { SharedMutex::WriteHolder w{&threadListLock_}; if (tryDecrToStop()) { threadList_.remove(thread); stoppedThreads_.add(thread); return; } } } }
void RemoveFromPool(const ThreadPtr& threadPtr) { m_Pool.remove_thread(threadPtr.get()); }