Blocks until the work queue is empty, and then calls Shutdown to stop the worker threads and Join to wait until they are finished. Any work Offer()'ed during DrainAndShutdown may or may not be processed.
| 144 | /// threads and Join to wait until they are finished. |
| 145 | /// Any work Offer()'ed during DrainAndShutdown may or may not be processed. |
| 146 | void DrainAndShutdown() { |
| 147 | { |
| 148 | std::unique_lock<std::mutex> l(lock_); |
| 149 | // If the ThreadPool is not initialized, then the queue must be empty. |
| 150 | DCHECK(initialized_ || work_queue_.Size() == 0); |
| 151 | while (work_queue_.Size() != 0) { |
| 152 | empty_cv_.Wait(l); |
| 153 | } |
| 154 | } |
| 155 | Shutdown(); |
| 156 | Join(); |
| 157 | } |
| 158 | |
| 159 | private: |
| 160 | /// Driver method for each thread in the pool. Continues to read work from the queue |