1#ifndef SBL_PRIMITIVES_BUFFERS_RING_BUFFER_HPP_
2#define SBL_PRIMITIVES_BUFFERS_RING_BUFFER_HPP_
71template<
typename T, u
int32_t Size,
typename MemoryBarrierImpl>
73 static_assert((Size & (Size - 1)) == 0,
"Size must be power of 2");
74 static_assert(Size > 1,
"Size must be greater than 1");
75 static_assert(Size <= 65536,
"Size must fit in practical memory constraints");
96 const uint32_t current_head = head_;
97 const uint32_t next_head = (current_head + 1) & (Size - 1);
100 if (next_head == tail_) {
105 buffer_[current_head] = item;
108 MemoryBarrierImpl::full_barrier();
127 const uint32_t current_tail = tail_;
130 if (current_tail == head_) {
135 item = buffer_[current_tail];
138 MemoryBarrierImpl::full_barrier();
141 tail_ = (current_tail + 1) & (Size - 1);
152 return head_ == tail_;
161 return ((head_ + 1) & (Size - 1)) == tail_;
172 return (head_ - tail_) & (Size - 1);
202 volatile uint32_t head_;
203 volatile uint32_t tail_;
210template<
typename MemoryBarrierImpl>
217template<
typename MemoryBarrierImpl>
224template<
typename EventType,
typename MemoryBarrierImpl>
Lock-free single-producer-single-consumer ring buffer.
void clear()
Clear all elements from buffer.
bool pop(T &item)
Pop element from buffer (consumer side)
bool full() const
Check if buffer is full.
RingBuffer()
Construct empty ring buffer.
bool empty() const
Check if buffer is empty.
constexpr uint32_t capacity() const
Get maximum buffer capacity.
uint32_t size() const
Get number of elements in buffer.
bool push(const T &item)
Push element to buffer (producer side)
Root namespace for all Sound Byte Libs functionality.