Class RingBuffer

Class Documentation

class RingBuffer

A simple circular buffer implementation used for queued processing of incoming lidar / imu data.

Public Functions

inline RingBuffer(std::size_t element_size, std::size_t num_elements)

Create a new RingBuffer instance

Parameters:
  • element_size – The size (in bytes) of each element

  • num_elements – Number of maximum elements in the buffer.

inline bool empty()

Check whether there is any data to be read from the buffer at head()

Returns:

true if there are no elements in the buffer

inline bool full()

Check if the ringbuffer is full If the buffer is full, adding new data to it will overwrite or corrupt data at the head() position. This function is only safe to call in the producing thread, i.e. no calls to push() may occur simultaneously.

Returns:

true if the buffer is full

inline uint8_t *head()
Returns:

A pointer to the current element to read from

inline uint8_t *tail()
Returns:

A pointer to the current element to write to

inline void pop()

Remove the current head element from the queue.

inline void push()

Add a new element (with data already filled at the location pointed to by tail()) to the buffer.

Protected Attributes

const std::size_t _element_size
const std::size_t _num_elements
std::atomic<std::size_t> _head
std::atomic<std::size_t> _tail
std::unique_ptr<uint8_t[]> _buf