Thread-safe FIFO coordination between producers and consumers.
More...
Thread-safe FIFO coordination between producers and consumers.
Event queues provide thread-safe FIFO coordination between producers and consumers.
Queue behavior summary:
Typical flow:
- Allocate with
sys_event_queue_init(capacity).
- Push events from producer threads/interrupt-safe contexts as supported.
- Pop events in one or more consumer workers.
- Call
sys_event_queue_shutdown() to stop intake and unblock waiters.
- Deinitialize with
sys_event_queue_deinit().
◆ sys_event_t
Event payload stored in a queue.
NULL is reserved to report an empty queue, timeout, or shutdown, so pushed events must be non-NULL.
Definition at line 68 of file event.h.
◆ sys_event_queue_deinit()
Deinitialize an event queue and release its resources.
- Parameters
-
| queue | Queue to deinitialize. |
◆ sys_event_queue_empty()
Report whether a queue is empty.
- Parameters
-
- Returns
true if the queue is empty, false otherwise.
◆ sys_event_queue_init()
Allocate a new event queue.
- Parameters
-
| capacity | Maximum number of events retained by the queue. |
- Returns
- New queue, or
NULL on allocation or initialization failure.
◆ sys_event_queue_lock()
Lock a queue for manual inspection.
- Parameters
-
- Returns
true on success, false on error.
Required around sys_event_queue_peek(), the only operation that does not lock internally - every other operation here (sys_event_queue_push(), sys_event_queue_pop(), etc.) is safe to call without holding this lock.
Thread-context use only (this may block); never call from an IRQ handler. On backends where pushes are IRQ-safe, this does not exclude a concurrent push/pop, only other sys_event_queue_lock() callers - it coordinates callers of this function with each other, not with the queue's own internal operations.
◆ sys_event_queue_peek()
Peek at the next queued event without removing it.
- Parameters
-
- Returns
- Next event, or
NULL if none is available.
The caller is responsible for holding the queue lock while peeking.
◆ sys_event_queue_pop()
Pop the next event, blocking until one is available or shutdown.
- Parameters
-
- Returns
- Next event, or
NULL if the queue is shut down and drained.
◆ sys_event_queue_push()
Push an event, overwriting the oldest entry if the queue is full.
- Parameters
-
| queue | Queue to write to. |
| event | Non-NULL event payload. |
- Returns
true on success, false on error or after shutdown.
◆ sys_event_queue_shutdown()
Prevent future pushes and wake blocked consumers.
- Parameters
-
◆ sys_event_queue_size()
Return the current event count.
- Parameters
-
- Returns
- Snapshot of the current number of queued events.
◆ sys_event_queue_timed_pop()
Pop the next event with a timeout.
- Parameters
-
| queue | Queue to read from. |
| timeout_ms | Timeout in milliseconds. 0 waits indefinitely. |
- Returns
- Next event, or
NULL on timeout, invalid queue, or shutdown.
◆ sys_event_queue_try_pop()
Pop the next event without blocking.
- Parameters
-
- Returns
- Next event, or
NULL if empty or invalid.
◆ sys_event_queue_try_push()
Try to push an event without overwriting.
- Parameters
-
| queue | Queue to write to. |
| event | Non-NULL event payload. |
- Returns
true on success, false if full, invalid, or shut down.
◆ sys_event_queue_unlock()
Unlock a queue after manual inspection.
- Parameters
-
- Returns
true on success, false on error.