CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Loading...
Searching...
No Matches
ds::ring_buffer::Cursors< Debug, Capacity, IxTy > Class Template Reference

A statically-sized, non-atomic ring buffer state machine. More...

#include <ring_buffer.h>

Public Types

using Ix = IxTy

Public Member Functions

void reset ()
 Reset cursors to an empty state.
bool is_empty ()
 Is this ring empty?
bool head_get (Ix &v)
 Try to retrieve the head index; returns true if available and false otherwise.
Ix head_get_unsafe ()
 Retrieve the head index while bypassing the emptiness check.
void head_advance ()
 Discard the element at the index returned by head_get().
bool tail_get (Ix &v)
 Try to retrieve the index of the tail, if nonempty.
bool tail_next (Ix &v)
 Try to retrieve the index beyond the tail, if there is room.
void tail_advance ()
 Make the next element available.

Detailed Description

template<typename Debug, std::size_t Capacity, typename IxTy = std::size_t>
class ds::ring_buffer::Cursors< Debug, Capacity, IxTy >

A statically-sized, non-atomic ring buffer state machine.

The actual element storage must be provided externally; all this does is manage the cursors. This representation uses an explicit empty flag, rather than considering equal cursors to be empty, so as to not need an extra element of store Capacity-many items.

The type of the cursors is parametric, but must be unsigned.

The consumer workflow is:

  • use head_get() to test emptiness and, if nonempty, read the index of the head element
  • make use of the element in the (external!) storage at that index
  • call head_advance() to discard the head element

The producer workflow is:

  • use tail_next() to retrieve the index for the next element, if there is room
  • populate the element in the (external!) storage at that index
  • call tail_advance() to make that element available to the consumer

Definition at line 39 of file ring_buffer.h.

Member Typedef Documentation

◆ Ix

template<typename Debug, std::size_t Capacity, typename IxTy = std::size_t>
using ds::ring_buffer::Cursors< Debug, Capacity, IxTy >::Ix = IxTy

Definition at line 48 of file ring_buffer.h.

Member Function Documentation

◆ head_advance()

template<typename Debug, std::size_t Capacity, typename IxTy = std::size_t>
void ds::ring_buffer::Cursors< Debug, Capacity, IxTy >::head_advance ( )
inline

Discard the element at the index returned by head_get().

Do not call this unless there was a matching call to head_get() that has returned true.

Definition at line 125 of file ring_buffer.h.

◆ head_get()

template<typename Debug, std::size_t Capacity, typename IxTy = std::size_t>
bool ds::ring_buffer::Cursors< Debug, Capacity, IxTy >::head_get ( Ix & v)
inline

Try to retrieve the head index; returns true if available and false otherwise.

Definition at line 99 of file ring_buffer.h.

References is_empty().

◆ head_get_unsafe()

template<typename Debug, std::size_t Capacity, typename IxTy = std::size_t>
Ix ds::ring_buffer::Cursors< Debug, Capacity, IxTy >::head_get_unsafe ( )
inline

Retrieve the head index while bypassing the emptiness check.

The caller must have reason to believe that the ring is not empty.

Definition at line 114 of file ring_buffer.h.

◆ is_empty()

template<typename Debug, std::size_t Capacity, typename IxTy = std::size_t>
bool ds::ring_buffer::Cursors< Debug, Capacity, IxTy >::is_empty ( )
inline

Is this ring empty?

Definition at line 90 of file ring_buffer.h.

Referenced by head_get(), and tail_get().

◆ reset()

template<typename Debug, std::size_t Capacity, typename IxTy = std::size_t>
void ds::ring_buffer::Cursors< Debug, Capacity, IxTy >::reset ( )
inline

Reset cursors to an empty state.

Definition at line 80 of file ring_buffer.h.

◆ tail_advance()

template<typename Debug, std::size_t Capacity, typename IxTy = std::size_t>
void ds::ring_buffer::Cursors< Debug, Capacity, IxTy >::tail_advance ( )
inline

Make the next element available.

Do not call this unless there was a matching call to tail_next() that returned true.

Definition at line 173 of file ring_buffer.h.

◆ tail_get()

template<typename Debug, std::size_t Capacity, typename IxTy = std::size_t>
bool ds::ring_buffer::Cursors< Debug, Capacity, IxTy >::tail_get ( Ix & v)
inline

Try to retrieve the index of the tail, if nonempty.

Definition at line 138 of file ring_buffer.h.

References is_empty().

◆ tail_next()

template<typename Debug, std::size_t Capacity, typename IxTy = std::size_t>
bool ds::ring_buffer::Cursors< Debug, Capacity, IxTy >::tail_next ( Ix & v)
inline

Try to retrieve the index beyond the tail, if there is room.

Returns true and sets the index if so, or returns false if not.

Definition at line 155 of file ring_buffer.h.


The documentation for this class was generated from the following file: