1#ifndef SBL_CORE_PRIMITIVES_BUFFERS_RING_BUFFER_HPP_
2#define SBL_CORE_PRIMITIVES_BUFFERS_RING_BUFFER_HPP_
78template<
typename T, common::types::BufferSize Size,
typename MemoryBarrierImpl>
80 static_assert((Size & (Size - 1)) == 0,
"Size must be power of 2");
81 static_assert(Size > 1,
"Size must be greater than 1");
82 static_assert(Size <= 65536,
"Size must fit in practical memory constraints");
107 if (next_head == tail_.load()) {
112 buffer_[current_head] = item;
118 head_.store(next_head);
137 if (current_tail == head_.load()) {
142 item = buffer_[current_tail];
149 tail_.store(next_tail);
160 return head_.load() == tail_.load();
170 return next_head == tail_.load();
183 return (h - t) & (Size - 1);
216 static void memory_barrier() {
217 MemoryBarrierImpl::full_barrier();
225 alignas(64) AtomicIndex head_;
226 alignas(64) AtomicIndex tail_;
233template<
typename MemoryBarrierImpl>
240template<
typename MemoryBarrierImpl>
247template<
typename EventType,
typename MemoryBarrierImpl>
Lock-free single-producer-single-consumer ring buffer.
void clear()
Clear all elements from buffer.
bool push(const T &item)
Push element to buffer (producer side)
RingBuffer()
Construct empty ring buffer.
bool pop(T &item)
Pop element from buffer (consumer side)
common::types::BufferIndex size() const
Get number of elements in buffer.
bool empty() const
Check if buffer is empty.
bool full() const
Check if buffer is full.
constexpr common::types::BufferIndex capacity() const
Get maximum buffer capacity.
uint32_t BufferIndex
ARM-native buffer index type.
uint32_t BufferSize
ARM-native buffer size type.
Root namespace for all Sound Byte Libs functionality.