3#include <condition_variable>
16 void Push(
const std::function<
void()>& command)
19 std::lock_guard<std::mutex> lock(m_Mutex);
20 m_Queue.push(command);
27 bool Pop(std::function<
void()>& command, std::chrono::milliseconds waitDuration)
29 std::unique_lock<std::mutex> lock(m_Mutex);
30 if (m_Cond.wait_for(lock, waitDuration, [
this]() { return !m_Queue.empty(); }))
32 command = m_Queue.front();
47 std::condition_variable m_Cond;
48 std::queue<std::function<void()>> m_Queue;
A simple thread-safe command queue.
Definition CommandQueue.hpp:13
void Push(const std::function< void()> &command)
Push a new command into the queue.
Definition CommandQueue.hpp:16
bool Pop(std::function< void()> &command, std::chrono::milliseconds waitDuration)
Definition CommandQueue.hpp:27
void NotifyAll()
Notifies all waiting threads.
Definition CommandQueue.hpp:40