data.buffer.cyclic ≡
template < typename T, auto WordSize, auto ReadWordSize, auto TotalSize, typename AddrType = uint64 > class unaligned_cyclic_buffer §source
A cyclic buffer with the following functionality:
- One data word can be written at a time until the buffer is full
- Words can be freed to create new write space in a FIFO manner
- Any valid element (written and not freed) can be read, even if not aligned to a word boundary
Parameters
-
typename TType of each element of the buffer.
-
auto WordSizeNumber of elements per data word.
-
auto ReadWordSizeNumber of elements to be returned per read. Must be <= to WordSize.
-
auto TotalSizeTotal size of memory in elements.
-
typename AddrType = uint64
Type to accumulate number of written and freed words. Ensure this will not overflow between calls to reset. Additionally, used to access and free buffer elements.
Aliases
-
using addr_t = AddrType §source
-
using word_t = unaligned_cyclic_buffer::unaligned_memory_t::word_t §source
-
using read_word_t = unaligned_cyclic_buffer::unaligned_memory_t::read_word_t §source
Methods
-
void reset() §source
Reset cyclic buffer. This is not thread-safe and should not be called while any other functions are running.
-
void write(T[WordSize] word) §source
Write one word. Maybe block until there is space in the buffer.
-
void free(unaligned_cyclic_buffer::addr_t addr) §source
Free words up to, but not including, the specified address. Caller should ensure that this address is valid.
Arguments
-
unaligned_cyclic_buffer::addr_t addr
Element address.
-
-
void wait(unaligned_cyclic_buffer::addr_t addr) §source
Block until a fully valid word has been written to the passed address.
Arguments
-
unaligned_cyclic_buffer::addr_t addr
Element address.
-
-
unaligned_cyclic_buffer::read_word_t read(unaligned_cyclic_buffer::addr_t addr) §source
Wait for the entry at
addrto be written and then read the value. The caller should ensure that this is not called for a free entry.Arguments
-
unaligned_cyclic_buffer::addr_t addr
Element address.
-
-
inline unaligned_cyclic_buffer::read_word_t nonblocking_read(unaligned_cyclic_buffer::addr_t addr) §source
Read the value at the specified address. This version of read does not block to wait for the entry to be written. It is also inline to reduce the cost of multiple callsites. The caller should ensure that the address is valid (written and not freed).
Arguments
-
unaligned_cyclic_buffer::addr_t addr
Element address.
-
template <typename T, auto Size, typename AddrType = uint64> class cyclic_buffer §source
This class is a wrapper around a unaligned_cyclic_buffer
with WordSize == 1.
Parameters
-
typename TType of each entry in the buffer.
-
auto SizeMaximum number of entries that can be stored.
-
typename AddrType = uint64
Type to accumulate number of written and freed words. Ensure this will not overflow between calls to reset. Additionally, used to access and free buffer elements.
Aliases
-
using addr_t = cyclic_buffer::unaligned_cyclic_buffer_t::addr_t §source
Methods
-
void reset() §source
Reset cyclic buffer. This is not thread-safe and should not be called while any other functions are running.
-
void write(T val) §source
Wait for a free entry and write one entry.
-
void free(cyclic_buffer::addr_t addr) §source
Free entries up to the specified address. Caller should ensure that this address is valid.
Arguments
-
cyclic_buffer::addr_t addr
Element address.
-
-
void wait(cyclic_buffer::addr_t addr) §source
Block until the passed address has been written to.
Arguments
-
cyclic_buffer::addr_t addr
Element address.
-
-
T read(cyclic_buffer::addr_t addr) §source
Wait for the entry at
addrto be written and then read the value. The caller should ensure that this is not called for a free entry.Arguments
-
cyclic_buffer::addr_t addr
Element address.
-
-
inline T nonblocking_read(cyclic_buffer::addr_t addr) §source
Read the value at the specified address. This version of read does not block to wait for the entry to be written. It is also inline to reduce the cost of multiple callsites. The caller should ensure that the address is valid (written and not freed).
Arguments
-
cyclic_buffer::addr_t addr
Element address.
-