core.ds.circ¶
Fixed-capacity ring-buffer queue.
Overview¶
core.ds.circ implements a circular (ring-buffer) FIFO queue with a fixed maximum capacity set at creation time. Elements are stored in a flat pre-allocated buffer. Head and tail indices advance with modulo arithmetic to wrap around the buffer, eliminating the need for compaction or shifting. Enqueue is rejected when the buffer is full.
Dependencies¶
memory.heap—kalloc,kfreecore.ds.types—TCircularQueue,PCircularQueuecore.util—memcpy,memsetarch.x86.util— architecture utilitiesio.syslog— test output (implementation only)core.strings— test output formatting (implementation only)
Functions and Procedures¶
circ_New¶
Creates a new circular queue with exactlyCapacity element slots. ElementSize is the size in bytes of each element. The buffer is zero-initialised.
circ_Enqueue¶
CopiesElementSize bytes from Data into the next free slot and advances the tail index. Returns false if the queue is full and the element is rejected.
circ_Dequeue¶
Copies the front element intoData and advances the head index. Returns false if the queue is empty.
circ_Peek¶
Returns a direct pointer to the front element without removing it. Returnsnil if the queue is empty.
circ_Size¶
Returns the number of elements currently in the queue.circ_IsFull¶
Returnstrue if the queue has reached its maximum capacity.
circ_IsEmpty¶
Returnstrue if the queue contains no elements.
circ_Free¶
Frees the element buffer and the queue structure.UnitTest¶
Runs the circular queue test suite and logs a pass/fail summary to syslog under the'CIRC' channel.
Notes¶
The capacity is fixed at creation. Unlike core.ds.cfifo, the circular queue never grows. Callers must choose a capacity sufficient for their maximum concurrent element count.
The pointer returned by circ_Peek is invalidated by any subsequent enqueue or dequeue that moves the head index.