diff options
Diffstat (limited to 'src/common/thread_worker.cpp')
| -rw-r--r-- | src/common/thread_worker.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/common/thread_worker.cpp b/src/common/thread_worker.cpp index 8f9bf447a..745918c7e 100644 --- a/src/common/thread_worker.cpp +++ b/src/common/thread_worker.cpp | |||
| @@ -29,6 +29,10 @@ ThreadWorker::ThreadWorker(std::size_t num_workers, const std::string& name) { | |||
| 29 | } | 29 | } |
| 30 | task = std::move(requests.front()); | 30 | task = std::move(requests.front()); |
| 31 | requests.pop(); | 31 | requests.pop(); |
| 32 | |||
| 33 | if (requests.empty()) { | ||
| 34 | wait_condition.notify_one(); | ||
| 35 | } | ||
| 32 | } | 36 | } |
| 33 | 37 | ||
| 34 | task(); | 38 | task(); |
| @@ -55,4 +59,9 @@ void ThreadWorker::QueueWork(std::function<void()>&& work) { | |||
| 55 | condition.notify_one(); | 59 | condition.notify_one(); |
| 56 | } | 60 | } |
| 57 | 61 | ||
| 62 | void ThreadWorker::WaitForRequests() { | ||
| 63 | std::unique_lock lock{queue_mutex}; | ||
| 64 | wait_condition.wait(lock, [this] { return stop || requests.empty(); }); | ||
| 65 | } | ||
| 66 | |||
| 58 | } // namespace Common | 67 | } // namespace Common |