Class providing ring buffer functionality. Supports single-threaded and multi-threaded (single producer, single consumer) use cases.
More...
#include <RingBuffer.hpp>
|
| RingBuffer (uint numberOfItems) |
| Creates a RingBuffer instance. Allocates the underlying buffer, not suitable for use in the real-time thread.
|
|
| RingBuffer (uint numberOfItems, T *buffer) |
| Creates a RingBuffer instance without allocating. Suitable for resizing a ring buffer in the real-time thread.
|
|
| ~RingBuffer () |
| RingBuffer destructor.
|
|
void | clear () |
| Clears all data in the ring buffer.
|
|
uint | getAvailableItemsToProduce () const |
| Returns the maximum number of items that can be added to the ring buffer.
|
|
void | produce (const T *sourceBuffer, uint numberOfItems) |
| Adds items to the ring buffer.
|
|
uint | getAvailableItemsToConsume () const |
| Returns the maximum number of items that can be read from the ring buffer.
|
|
void | consume (T *destBuffer, uint numberOfItems) |
| Reads items from the ring buffer and updates the read pointer.
|
|
void | read (T *destBuffer, uint numberOfItems) |
| Reads items from the ring buffer without updating the read pointer.
|
|
void | discard (uint numberOfItems) |
| Discards items from the ring buffer. Steps the read pointer without reading the items.
|
|
template<typename T>
class switchboard::RingBuffer< T >
Class providing ring buffer functionality. Supports single-threaded and multi-threaded (single producer, single consumer) use cases.
RingBuffer class.
◆ RingBuffer() [1/2]
Creates a RingBuffer instance. Allocates the underlying buffer, not suitable for use in the real-time thread.
- Parameters
-
numberOfItems | The number of items that the ring buffer can hold. |
◆ RingBuffer() [2/2]
Creates a RingBuffer instance without allocating. Suitable for resizing a ring buffer in the real-time thread.
Does not delete the buffer on destruction. Make sure to handle deletion.
- Parameters
-
numberOfItems | The number of items that the ring buffer can hold. |
buffer | The underlying buffer the ring buffer is operating on. |
◆ consume()
Reads items from the ring buffer and updates the read pointer.
- Parameters
-
destBuffer | [inout] The buffer where the read items will be copied to. |
numberOfItems | The number of items that should be consumed. |
◆ discard()
Discards items from the ring buffer. Steps the read pointer without reading the items.
- Parameters
-
numberOfItems | The number of items that should be discarded. |
◆ getAvailableItemsToConsume()
Returns the maximum number of items that can be read from the ring buffer.
- Returns
- The number items that can be consumed.
◆ getAvailableItemsToProduce()
Returns the maximum number of items that can be added to the ring buffer.
- Returns
- The number of items that can be produced.
◆ produce()
Adds items to the ring buffer.
- Parameters
-
sourceBuffer | The buffer where the items are copied from. |
numberOfItems | The number of items that should be added to the ring buffer. |
◆ read()
Reads items from the ring buffer without updating the read pointer.
- Parameters
-
destBuffer | [inout] The buffer where the read items will be copied to. |
numberOfItems | The number of items that should be consumed. |