libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
Loading...
Searching...
No Matches
console::CommandQueue Class Reference

Thread-safe FIFO queue for dispatching console commands to a worker thread. More...

#include <console.hpp>

Collaboration diagram for console::CommandQueue:
[legend]

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}

Detailed Description

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.

Member Function Documentation

◆ pop()

bool console::CommandQueue::pop ( Command & cmd)

Pop the next command (blocking on native, non-blocking on Emscripten).

Parameters
cmdOutput: the dequeued command.
Returns
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.

◆ push()

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.

◆ shutdown()

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.

Member Data Documentation

◆ active

std::atomic<bool> console::CommandQueue::active {true}
private

Definition at line 101 of file console.hpp.

Referenced by pop(), and shutdown().

◆ cv

std::condition_variable console::CommandQueue::cv
private

Definition at line 97 of file console.hpp.

Referenced by pop(), push(), and shutdown().

◆ queue

std::queue<Command> console::CommandQueue::queue
private

Definition at line 94 of file console.hpp.

Referenced by pop(), and push().

◆ queue_mutex

std::mutex console::CommandQueue::queue_mutex
private

Definition at line 96 of file console.hpp.

Referenced by pop(), push(), and shutdown().


The documentation for this class was generated from the following files: