27 threads_(GetNonNullAllocator()),
42 if (thread_count < threads_.size()) {
50 while (thread_count > threads_.size()) {
53 Post(&active_threads_sema_);
64 for (
size_t i = 0; i < threads_.size(); ++i) {
65 Wait(&active_threads_sema_);
76 for (
size_t i = 0; i < threads_.size(); ++i) {
77 Post(&active_threads_sema_);
109 Wait(&active_threads_sema_);
111 Post(&active_threads_sema_);
115 void WorkerPool::KillAllThreads() {
122 for (
size_t i = 0; i < threads_.size(); ++i) {
125 Post(&active_threads_sema_);
129 for (
const auto& thread_id : threads_) {
139 while (active_threads_sema_.
TryWait()) {}
142 void WorkerPool::Wait(port::Semaphore* sema) {
143 bool semaphore_wait_succeeded = sema->Wait();
144 DCHECK(semaphore_wait_succeeded);
147 void WorkerPool::Post(port::Semaphore* sema) {
148 bool semaphore_post_succeeded = sema->Post();
149 DCHECK(semaphore_post_succeeded);
void YieldThread()
Causes the calling thread to relinquish the CPU if there are other threads waiting to execute...
Interface to enable pluggable worker behavior.
bool IsLocked()
Returns whether the Mutex is currently locked. Does not block.
bool JoinThread(ThreadId id)
Windows-specific public functions.
A LockGuard locks a mutex when created, and unlocks it when destroyed.
ThreadId SpawnThreadStd(const ThreadStdFunc *func)
void ResizeThreadPool(size_t thread_count)
Changes the number of theads in the pool.
#define CHECK_NOTNULL(val)
Check that the input is not NULL.
void Suspend()
Suspends all threads until Resume() is called.
void Resume()
Resumes all threads.
WorkerPool(Worker *worker)
Constructor/destructor.
bool IsThreadNamingSupported()
Thread naming functions.
bool IsSuspended() const
Return true if pool's threads are suspended.
bool SetThreadName(const std::string &name)
Sets the name of the current thread.
bool TryWait()
Does not block.
virtual void DoWork()=0
Called repeatedly in worker thread loop, whenever GetWorkSemaphore() is signaled to indicate that the...
const std::string & GetName() const
Gets a descriptive name for the pool from the worker.
virtual void ThreadEntryPoint()
ThreadEntryPoint() is run on each created thread.