mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-26 15:55:31 +01:00
Extended WorkQueueThread class with Clear(), Cancel() and IsCancelled().
This commit is contained in:
parent
5b757024c4
commit
213610e95d
@ -27,6 +27,7 @@ public:
|
|||||||
{
|
{
|
||||||
Shutdown();
|
Shutdown();
|
||||||
m_shutdown.Clear();
|
m_shutdown.Clear();
|
||||||
|
m_cancelled.Clear();
|
||||||
m_function = std::move(function);
|
m_function = std::move(function);
|
||||||
m_thread = std::thread(&WorkQueueThread::ThreadLoop, this);
|
m_thread = std::thread(&WorkQueueThread::ThreadLoop, this);
|
||||||
}
|
}
|
||||||
@ -34,6 +35,7 @@ public:
|
|||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void EmplaceItem(Args&&... args)
|
void EmplaceItem(Args&&... args)
|
||||||
{
|
{
|
||||||
|
if (!m_cancelled.IsSet())
|
||||||
{
|
{
|
||||||
std::lock_guard lg(m_lock);
|
std::lock_guard lg(m_lock);
|
||||||
m_items.emplace(std::forward<Args>(args)...);
|
m_items.emplace(std::forward<Args>(args)...);
|
||||||
@ -41,6 +43,24 @@ public:
|
|||||||
m_wakeup.Set();
|
m_wakeup.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Clear()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
std::lock_guard lg(m_lock);
|
||||||
|
m_items = std::queue<T>();
|
||||||
|
}
|
||||||
|
m_wakeup.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Cancel()
|
||||||
|
{
|
||||||
|
m_cancelled.Set();
|
||||||
|
Clear();
|
||||||
|
Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsCancelled() const { return m_cancelled.IsSet(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Shutdown()
|
void Shutdown()
|
||||||
{
|
{
|
||||||
@ -81,6 +101,7 @@ private:
|
|||||||
std::thread m_thread;
|
std::thread m_thread;
|
||||||
Common::Event m_wakeup;
|
Common::Event m_wakeup;
|
||||||
Common::Flag m_shutdown;
|
Common::Flag m_shutdown;
|
||||||
|
Common::Flag m_cancelled;
|
||||||
std::mutex m_lock;
|
std::mutex m_lock;
|
||||||
std::queue<T> m_items;
|
std::queue<T> m_items;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user