Skip to main content

Module queue

Module queue 

Source
Expand description

queue.c: the queue, and the semaphore and mutex built on it.

In FreeRTOS a semaphore is a queue with a zero-size item, and a mutex is that plus a holder and priority inheritance. Kairos keeps the same shape, because the trace does: a semaphore give fires QUEUE_SEND and a mutex take fires QUEUE_RECEIVE, and a conformance diff would notice any tidier arrangement.

§A blocking call with no stack to block on

xQueueReceive( q, &v, 100 ) blocks: the C task stops inside the call, and when it is woken it loops back to the top, re-checks the queue, and either returns the item or blocks again. This kernel has no stack to suspend, so the loop is turned inside out — a blocking call returns Blocked and the caller invokes it again, unchanged, when it next runs:

ⓘ
// in a task body, at some `pc`:
match k.queue_receive(q, 100)? {
    Blocked => {}                 // stay at this pc; the kernel parked us
    Ready(value) => { ...; self.pc = next; }
}

The task is off the ready list when Blocked comes back, so the runner will not step it again until the kernel wakes it — which is exactly when the C thread would have resumed. What the C keeps on its stack across the block (the timeout, the remaining ticks, whether inheritance happened) this kernel keeps in the TCB, in Wait, because that is the stack frame.

Re-exports§

pub use Wait::Blocked;
pub use Wait::Ready;

Enums§

Kind
What a queue is underneath (ucQueueType).
Position
Where an item goes (xCopyPosition).
Wait
What a blocking call answers.