|
Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
Double-buffered struct with a sequence number, for one writer and one reader. More...
Double-buffered struct with a sequence number, for one writer and one reader.
The bridge between the control tick and the audio callback for a set of values that belong together. The writer publishes a struct; the reader takes all of it or none of it, so a block never works from values of two ticks.
Two copies of T and a sequence number. publish() writes the copy that is not current and then makes it current with one 32-bit store. read() copies the current one, and does nothing when the sequence has not moved since its last read, so a patch at rest costs a load and a compare a block.
Ordering between a copy and the sequence comes from the fences system/ring_buffer.hpp uses: compiler-only on a single core, a barrier on a host. Each is needed there: on a weakly ordered machine a core may satisfy read()'s copy after its second look at the sequence, and a writer's stores into a copy may be seen before its earlier store of the sequence, and either lets a reader accept a copy that was being written (seen on AArch64 in the threaded unit test).
T is trivially copyable. publish() compares by bytes. The copies are byte copies of what the writer passed, so a struct the writer keeps and publishes again compares exactly; padding that differs, as it can on the first publish, only costs a publish that changed nothing.
| T | Trivially copyable struct |
Definition at line 67 of file snapshot.hpp.
#include <snapshot.hpp>
Public Member Functions | |
| bool | publish (const T &value) |
| bool | read (T &into) |
| uint32_t | sequence () const |
|
inline |
Writer. Make value the current copy. Returns false, and writes nothing, when it equals the current copy byte for byte.
Definition at line 75 of file snapshot.hpp.
References sbl::control::Snapshot< T >::sequence().
|
inline |
Reader. Copy the current value into into if it has been published since the last read, or if this is the first read. Returns whether into was written.
Definition at line 93 of file snapshot.hpp.
References sbl::control::Snapshot< T >::sequence().
|
inline |
How many times a value has been published. Wraps at 2^32.
Definition at line 114 of file snapshot.hpp.
Referenced by sbl::control::Snapshot< T >::publish(), and sbl::control::Snapshot< T >::read().