3#include <condition_variable>
15 bool Push(
const std::function<
void()>& command)
18 std::lock_guard<std::mutex> lock(m_Mutex);
23 m_Queue.push(command);
30 bool Pop(std::function<
void()>& command)
32 std::unique_lock<std::mutex> lock(m_Mutex);
33 m_Cond.wait(lock, [
this]() {
return m_Closed || !m_Queue.empty(); });
40 command = std::move(m_Queue.front());
48 std::lock_guard<std::mutex> lock(m_Mutex);
56 std::condition_variable m_Cond;
57 std::queue<std::function<void()>> m_Queue;
58 bool m_Closed =
false;
A simple thread-safe command queue.
Definition command_queue.hpp:12
bool Pop(std::function< void()> &command)
Blocks until a command is available or the queue is closed.
Definition command_queue.hpp:30
bool Push(const std::function< void()> &command)
Push a new command into the queue.
Definition command_queue.hpp:15