Base module

ipc::Queue

IPC queue is for safely passing templated actions between threads and processes.

Queue

#include <icy/ipc.h>

Subclassed by: SyncQueue< TAction >

IPC queue is for safely passing templated actions between threads and processes.

Public Methods

ReturnNameDescription
Queue inline
voidpush virtual inlinePushes an action onto the queue and triggers a post notification. Takes ownership of action; the queue deletes it after execution. Thread-safe.
TAction *pop virtual inlineRemoves and returns the next action from the front of the queue. The caller takes ownership of the returned pointer. Thread-safe.
voidrunSync virtual inlineDrains the queue by invoking and deleting every pending action in order. Must be called from the thread that owns the event loop.
voidclose virtual inlineCloses the underlying notification handle. No-op in the base implementation.
voidpost virtual inlineSignals the event loop that new actions are available. No-op in the base implementation.
voidwaitForSync inlineBlocks the calling thread until the queue is empty or the timeout elapses. Polls every 10 ms. Logs a warning if the timeout is reached.

Queue

inline

inline Queue()

push

virtual inline

virtual inline void push(TAction * action)

Pushes an action onto the queue and triggers a post notification. Takes ownership of action; the queue deletes it after execution. Thread-safe.

Parameters

  • action Heap-allocated action to enqueue.

pop

virtual inline

virtual inline TAction * pop()

Removes and returns the next action from the front of the queue. The caller takes ownership of the returned pointer. Thread-safe.

Returns

Pointer to the next action, or nullptr if the queue is empty.


runSync

virtual inline

virtual inline void runSync()

Drains the queue by invoking and deleting every pending action in order. Must be called from the thread that owns the event loop.


close

virtual inline

virtual inline void close()

Closes the underlying notification handle. No-op in the base implementation.


post

virtual inline

virtual inline void post()

Signals the event loop that new actions are available. No-op in the base implementation.


waitForSync

inline

inline void waitForSync(std::chrono::milliseconds timeout)

Blocks the calling thread until the queue is empty or the timeout elapses. Polls every 10 ms. Logs a warning if the timeout is reached.

Parameters

  • timeout Maximum time to wait (default: 5000 ms).

Protected Attributes

ReturnNameDescription
std::mutex_mutex
std::deque< TAction * >_actions

_mutex

std::mutex _mutex

_actions

std::deque< TAction * > _actions