diff options
| author | Scott Mansell <phiren@gmail.com> | 2023-01-23 19:48:07 +1300 |
|---|---|---|
| committer | Scott Mansell <phiren@gmail.com> | 2023-02-04 14:31:16 +1300 |
| commit | 512273a5077e1aaf6ab8506595d7d1e36e4d7a02 (patch) | |
| tree | c95ceb801452b256b931f421a508cc522dca0e27 /Source/Core/Common/WorkQueueThread.h | |
| parent | aece99fe41d753866a545b3c8e821aa4a42e0512 (diff) | |
WorkQueueThread: Add flush capability
Diffstat (limited to 'Source/Core/Common/WorkQueueThread.h')
| -rw-r--r-- | Source/Core/Common/WorkQueueThread.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Source/Core/Common/WorkQueueThread.h b/Source/Core/Common/WorkQueueThread.h index 6039f7b3b9..f74c164e60 100644 --- a/Source/Core/Common/WorkQueueThread.h +++ b/Source/Core/Common/WorkQueueThread.h @@ -70,6 +70,19 @@ public: } } + // Doesn't return until the most recent function invocation has finished. + void Flush() + { + if (m_thread.joinable()) + { + m_flush.Set(); + Clear(); + m_flushed.Wait(); + } + } + + bool IsFlushing() const { return m_flush.IsSet() || m_shutdown.IsSet(); } + private: void ThreadLoop() { @@ -83,7 +96,14 @@ private: { std::unique_lock lg(m_lock); if (m_items.empty()) + { + if (m_flush.IsSet()) + { + m_flush.Clear(); + m_flushed.Set(); + } break; + } T item{std::move(m_items.front())}; m_items.pop(); lg.unlock(); @@ -101,6 +121,8 @@ private: Common::Event m_wakeup; Common::Flag m_shutdown; Common::Flag m_cancelled; + Common::Flag m_flush; + Common::Event m_flushed; std::mutex m_lock; std::queue<T> m_items; }; |
