|
libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
|
Thread-safe FIFO queue for dispatching console commands to a worker thread. More...
#include <console.hpp>
Classes | |
| struct | Command |
| A single command entry with its text and completion callback. More... | |
Public Member Functions | |
| void | push (const Command &cmd) |
| Push a command onto the queue (thread-safe). | |
| bool | pop (Command &cmd) |
| Pop the next command (blocking on native, non-blocking on Emscripten). | |
| void | shutdown () |
| Signal the worker to drain and stop. | |
Private Attributes | |
| std::queue< Command > | queue |
| std::mutex | queue_mutex |
| std::condition_variable | cv |
| std::atomic< bool > | active {true} |
Thread-safe FIFO queue for dispatching console commands to a worker thread.
Commands are pushed from the rendering / event thread and consumed by a dedicated background thread that invokes the associated callback.
Definition at line 72 of file console.hpp.
| bool console::CommandQueue::pop | ( | Command & | cmd | ) |
Pop the next command (blocking on native, non-blocking on Emscripten).
| cmd | Output: the dequeued command. |
true if a command was retrieved; false if the queue was shut down. Definition at line 80 of file console.cpp.
References active, cv, queue, and queue_mutex.
| void console::CommandQueue::push | ( | const Command & | cmd | ) |
Push a command onto the queue (thread-safe).
Definition at line 70 of file console.cpp.
References cv, queue, and queue_mutex.
| void console::CommandQueue::shutdown | ( | ) |
Signal the worker to drain and stop.
Definition at line 101 of file console.cpp.
References active, cv, and queue_mutex.
|
private |
Definition at line 101 of file console.hpp.
Referenced by pop(), and shutdown().
|
private |
Definition at line 97 of file console.hpp.
Referenced by pop(), push(), and shutdown().
|
private |
Definition at line 94 of file console.hpp.
|
private |
Definition at line 96 of file console.hpp.
Referenced by pop(), push(), and shutdown().