CQueue
CQueue(size_t capacity = 0);
Creates a concurrent FIFO with an initial node reservation. The capacity argument is not a fixed upper bound on later allocation.
System & concurrency
Concurrent FIFO, blocking, priority, and timed work queues.
#include <mc/queue.h>Choose CLQueue for blocking FIFO consumption, CPriorityQueue for bounded priority order, and CTimedQueue for delayed callbacks.
Stop all queue users before destroying a queue. CPriorityQueue copies payloads and does not own pointed-to objects. CLQueue<T*> deletes pointers still queued at destruction.
template<class T> class CQueueCQueue(size_t capacity = 0);
Creates a concurrent FIFO with an initial node reservation. The capacity argument is not a fixed upper bound on later allocation.
void push(const T& v);
Copies an item into the queue. This wrapper does not report the underlying push success flag, so it cannot be used to confirm delivery after resource exhaustion.
CQueue& operator<<(const T& v);
Calls push() and returns the queue for chaining. It has the same delivery-reporting limitation as push().
bool pop(T& v);
Attempts to remove the oldest item without waiting. Returns false when no item is available.
bool empty();
Takes a momentary emptiness observation; concurrent producers or consumers can change it immediately. Use the result of pop() to decide whether an item was obtained.
template<class I> requires(std::is_trivially_copyable_v<I> && std::is_trivially_copy_assignable_v<I> && std::is_nothrow_default_constructible_v<I>) class CPriorityQueueusing Item = I;
explicit CPriorityQueue(size_t capacity = 1024);
CPriorityQueue(const CPriorityQueue&) = delete;
CPriorityQueue(CPriorityQueue&&) = delete;
Allocates a fixed positive capacity for concurrent producers and consumers. Zero capacity raises CError; successful push/pop operations do not allocate.
CPriorityQueue& operator=(const CPriorityQueue&) = delete;
CPriorityQueue& operator=(CPriorityQueue&&) = delete;
[[nodiscard]] bool push(const Item& item, double priority);
Queues a copy in descending priority order, FIFO for ties. False means storage is occupied or reserved. NaN priorities throw.
bool pop(Item& item, double& priority) noexcept;
bool pop(Item& item) noexcept;
Never waits. False leaves the output arguments unchanged.
bool empty() const noexcept;
Reports whether the queue is empty at the instant observed. A concurrent operation can change the result immediately.
size_t capacity() const noexcept;
template<class I> class CLQueueusing Item = I;
static constexpr bool ItemPointer = std::is_pointer_v<Item>;
CLQueue();
Creates an empty enabled blocking queue. Consumers wait in pop() until an item arrives or the queue is disabled.
~CLQueue();
Destroys queued items. For pointer item types, also deletes every pointee left in the queue; stop all producers and consumers before destruction.
bool empty() const;
bool pop(Item& item);
template<class R, class P> bool pop(Item& item, const std::chrono::duration<R, P>& dt);
bool pop(Item& item, double dt);
Waits for the oldest item and moves it into the output. Returns false when disabled or a timed wait expires; a false result leaves the output unchanged. Numeric timeouts are in seconds.
bool tryPop(Item& item);
Removes the oldest item if immediately available and enabled. Returns false without modifying the output when empty or disabled.
void push(const Item& v);
void push(Item&& v);
Copies or moves an item into the FIFO and wakes one consumer. Pushes are still accepted after disable(), although those items cannot be popped.
Queues an item through push() and returns this queue for chaining.
void disable();
Wakes waiting consumers and prevents further pops, including queued items. Stop producers as well; push does not reject a disabled queue.
class CTimedQueueusing Func = std::function<void()>;
CTimedQueue();
CTimedQueue(const CTimedQueue&) = delete;
Creates a stopped timed queue. Call start() to begin dispatching scheduled entries to the handler.
~CTimedQueue();
CTimedQueue& operator=(const CTimedQueue&) = delete;
void start();
Starts the dispatcher; repeated calls while running have no effect. Tasks may be queued before startup.
void stop();
Requests dispatcher shutdown and joins its thread. This is not a guarantee that all scheduled tasks ran or that tasks launched through addFuture() have completed.
void add(Func f, double dt = 0.0);
Schedules a callable for approximately dt seconds from now. Execution can be delayed by earlier work; this form supplies no completion handle.
std::shared_ptr<Future> addFuture(Func f, double dt = 0.0);
Schedules a callable and returns a shared completion handle. Its await() can wait for dispatch and completion; it does not retrieve a return value or rethrow a callback exception.
void clear();
Discards callbacks that have not been dispatched. Do not wait on completion handles for discarded work.
class Futurevoid await();
Waits for dispatch and callback completion. This waits on the future without retrieving a stored callback exception.
void init_(Future_&& f);
Attaches the asynchronous task and releases the dispatch waiter. This is scheduler support; clients normally obtain a future from addFuture() rather than initialize one themselves.