CircularBuffer Class Reference
HiCR
|
Generic class type for circular buffer. More...
#include <circularBuffer.hpp>
Public Member Functions | |
CircularBuffer (size_t capacity, __volatile__ size_t *headAdvanceCounter, __volatile__ size_t *tailAdvanceCounter) | |
__INLINE__ size_t | getHeadPosition () const noexcept |
__INLINE__ size_t | getTailPosition () const noexcept |
__INLINE__ void | advanceHead (const size_t n=1) |
__INLINE__ void | advanceTail (const size_t n=1) |
__INLINE__ size_t | getCapacity () const noexcept |
__INLINE__ size_t | getDepth () const noexcept |
__INLINE__ bool | isFull () const noexcept |
__INLINE__ bool | isEmpty () const noexcept |
Static Protected Member Functions | |
static __INLINE__ size_t | calculateDepth (const size_t headAdvanceCounter, const size_t tailAdvanceCounter) |
Detailed Description
Generic class type for circular buffer.
Abstracts away the implementation of a circular buffer with two pointers
- Head Advance Counter: How many positions has the head been advanced
- Tail Advance Counter: How many positions has the tail been advanced Storage for these pointers shall be provided by the caller as pointers and will be considered volatile (this is useful for RDMA changes to the internal state of the circular buffer).
Constructor & Destructor Documentation
◆ CircularBuffer()
|
inline |
Constructor for the circular buffer class
- Parameters
-
[in] capacity The maximum capacity (elements) in the buffer [in] headAdvanceCounter A pointer to storage for the head advance counter [in] tailAdvanceCounter A pointer to storage fot the tail advance counter
Member Function Documentation
◆ advanceHead()
|
inline |
This function increases the circular buffer depth (e.g., when an element is pushed) by advancing a virtual head. The head cannot advance in such a way that the depth exceeds capacity.
- Parameters
-
[in] n The number of positions to advance
◆ advanceTail()
|
inline |
This function advances buffer tail (e.g., when an element is popped). It goes back around if the capacity is exceeded The tail cannot advanced more than the current depth (that would mean that more elements were consumed than pushed).
- Parameters
-
[in] n The number of positions to advance the head of the circular buffer
◆ calculateDepth()
|
inlinestaticprotected |
Calculate depth of circular buffer
- Parameters
-
[in] headAdvanceCounter head index [in] tailAdvanceCounter tail index
- Returns
- depth of buffer (in elements)
◆ getCapacity()
|
inlinenoexcept |
- Returns
- The capacity of the circular buffer.
This is a one-sided blocking call that need not be made collectively.
This function when called on a valid circular buffer instance will never fail.
◆ getDepth()
|
inlinenoexcept |
Returns the current circular buffer depth.
- Note
- This is not a thread-safe call
This is a getter function that should complete in
- Returns
- The number of tokens in this circular buffer.
This function when called on a valid circular buffer instance will never fail.
◆ getHeadPosition()
|
inlinenoexcept |
- Returns
- The current position of the buffer head
Returns the position of the buffer head to set as offset for sending/receiving operations.
This is a one-sided blocking call that need not be made collectively.
This is a getter function that should complete in
This function when called on a valid circular buffer instance will never fail.
◆ getTailPosition()
|
inlinenoexcept |
- Returns
- The current position of the buffer head
Returns the position of the buffer head to set as offset for sending/receiving operations.
This is a one-sided blocking call that need not be made collectively.
This is a getter function that should complete in
This function when called on a valid circular buffer instance will never fail.
◆ isEmpty()
|
inlinenoexcept |
This function can be used to quickly check whether the circular buffer is empty.
It does not affects the internal state of the circular buffer
- Returns
- true, if the buffer is empty
- false, if the buffer is not empty
◆ isFull()
|
inlinenoexcept |
This function can be used to quickly check whether the circular buffer is full.
It affects the internal state of the circular buffer because it detects any updates in the internal state of the buffers
- Returns
- true, if the buffer is full
- false, if the buffer is not full
The documentation for this class was generated from the following file:
- /home/runner/work/HiCR/HiCR/include/hicr/frontends/channel/circularBuffer.hpp
Generated by