Driver method for each thread in the pool. Continues to read work from the queue until the pool is shutdown.
| 160 | /// Driver method for each thread in the pool. Continues to read work from the queue |
| 161 | /// until the pool is shutdown. |
| 162 | void WorkerThread(int thread_id) { |
| 163 | while (!IsShutdown()) { |
| 164 | T workitem; |
| 165 | if (work_queue_.BlockingGet(&workitem)) { |
| 166 | work_function_(thread_id, workitem); |
| 167 | } |
| 168 | if (work_queue_.Size() == 0) { |
| 169 | /// Take lock to ensure that DrainAndShutdown() cannot be between checking |
| 170 | /// GetSize() and wait()'ing when the condition variable is notified. |
| 171 | /// (It will hang if we notify right before calling wait().) |
| 172 | std::unique_lock<std::mutex> l(lock_); |
| 173 | empty_cv_.NotifyAll(); |
| 174 | } |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | /// Returns value of shutdown_ under a lock, forcing visibility to threads in the pool. |
| 179 | bool IsShutdown() { |
nothing calls this directly
no test coverage detected