|
Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
Lock-free SPSC event queue from one producing context into the control tick. More...
Lock-free SPSC event queue from one producing context into the control tick.
One producing context pushes (the main loop, which parses USB MIDI); the control tick drains in Stage::Drain, so control state is only written from the control context.
A full queue drops the newest event: the push is rejected and counted. Only the consumer may move the tail, so dropping the oldest would need a lock. Size the queue so that overflow means a stalled tick. drain() pops at most capacity() events per call, so a producer that keeps pushing cannot stretch the tick.
| T | Event type (copied in and out) |
| Size | Slot count, a power of 2 greater than 1; capacity() is Size - 1 |
Definition at line 45 of file event_queue.hpp.
#include <event_queue.hpp>
Public Member Functions | |
| bool | push (const T &event) |
| Push one event (producer side) | |
| template<typename Fn > | |
| uint32_t | drain (Fn &&fn) |
| Call fn(event) for up to capacity() queued events, oldest first (consumer side) | |
| bool | pop (T &event) |
| Pop one event (consumer side) | |
| bool | empty () const |
| True if no event is queued; a snapshot from either side. | |
| uint32_t | dropped () const |
| Pushes rejected because the queue was full, since boot. | |
Static Public Member Functions | |
| static constexpr uint32_t | capacity () |
| Events the queue holds: Size - 1. | |
|
inline |
Push one event (producer side)
| event | Event to copy in |
Definition at line 52 of file event_queue.hpp.
|
inline |
Call fn(event) for up to capacity() queued events, oldest first (consumer side)
| fn | Callable taking (const T&) |
Definition at line 66 of file event_queue.hpp.
References sbl::control::EventQueue< T, Size >::capacity().
|
inline |
Pop one event (consumer side)
| [out] | event | Receives the oldest event |
Definition at line 81 of file event_queue.hpp.
|
inline |
True if no event is queued; a snapshot from either side.
Definition at line 84 of file event_queue.hpp.
|
inline |
Pushes rejected because the queue was full, since boot.
Definition at line 87 of file event_queue.hpp.
|
inlinestaticconstexpr |
Events the queue holds: Size - 1.
Definition at line 90 of file event_queue.hpp.
Referenced by sbl::control::EventQueue< T, Size >::drain().