|
Sound Byte Libs 0.5.1-121-g3358a44
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
Lock-free single-producer, single-consumer ring buffer. More...
Lock-free single-producer, single-consumer ring buffer.
Carries data from one execution context to another without blocking either: ISR → main on hardware, thread → thread on the workbench. Every operation is bounded and allocation-free.
The indices are relaxed std::atomic<uint32_t> — no torn or invented accesses, and no data race in the C++ sense. Ordering between the slot contents and the index that publishes them comes from a fence pair:
producer: write slot → release fence → store head consumer: load head → acquire fence → read slot → release fence → store tail
The fence strength follows the target:
atomic_signal_fence, compiler-only, zero instructions. A DMB would be the wrong strength, not a safer one (interrupt research doc §5.3).atomic_thread_fence (DMB on AArch64).One slot is reserved to tell full from empty: capacity is Size − 1.
Usage:
| T | Element type (copied in and out) |
| Size | Slot count, a power of 2 |
Definition in file ring_buffer.hpp.
#include <atomic>#include <cstdint>Go to the source code of this file.
Classes | |
| class | sbl::primitives::buffers::RingBuffer< T, Size > |
Namespaces | |
| namespace | sbl |
| Root namespace for all Sound Byte Libs code. | |
| namespace | sbl::primitives |
| Hardware-side primitives: buffers and integer math. | |
| namespace | sbl::primitives::buffers |
| Ring buffers. | |
| namespace | sbl::primitives::buffers::detail |
Functions | |
| void | sbl::primitives::buffers::detail::ring_acquire_fence () |
| void | sbl::primitives::buffers::detail::ring_release_fence () |