v2.0.0
Loading...
Searching...
No Matches
UTILSLIB::CircularBuffer< T > Class Template Reference

Thread-safe lock-free circular (ring) buffer for producer-consumer data exchange between threads. More...

#include <circularbuffer.h>

Public Types

typedef QSharedPointer< CircularBuffer > SPtr
typedef QSharedPointer< const CircularBuffer > ConstSPtr

Public Member Functions

 CircularBuffer (unsigned int uiMaxNumElements)
 ~CircularBuffer ()
bool push (const T *pArray, unsigned int size)
bool push (const T &newElement)
bool pop (T &element)
void clear ()
void pause (bool)
int getFreeElementsRead ()
int getFreeElementsWrite ()

Detailed Description

template<typename T>
class UTILSLIB::CircularBuffer< T >

Thread-safe lock-free circular (ring) buffer for producer-consumer data exchange between threads.

TEMPLATE CIRCULAR BUFFER

Definition at line 70 of file circularbuffer.h.

Member Typedef Documentation

◆ ConstSPtr

template<typename T>
typedef QSharedPointer<const CircularBuffer> UTILSLIB::CircularBuffer< T >::ConstSPtr

Const shared pointer type for CircularBuffer.

Definition at line 74 of file circularbuffer.h.

◆ SPtr

template<typename T>
typedef QSharedPointer<CircularBuffer> UTILSLIB::CircularBuffer< T >::SPtr

Shared pointer type for CircularBuffer.

Definition at line 73 of file circularbuffer.h.

Constructor & Destructor Documentation

◆ CircularBuffer()

template<typename T>
UTILSLIB::CircularBuffer< T >::CircularBuffer ( unsigned int uiMaxNumElements)
explicit

Constructs a CircularBuffer.

Parameters
[in]uiMaxNumElementslength of buffer.

Definition at line 176 of file circularbuffer.h.

◆ ~CircularBuffer()

template<typename T>
UTILSLIB::CircularBuffer< T >::~CircularBuffer ( )

Destroys the CircularBuffer.

Definition at line 191 of file circularbuffer.h.

Member Function Documentation

◆ clear()

template<typename T>
void UTILSLIB::CircularBuffer< T >::clear ( )
inline

Clears the buffer.

Definition at line 269 of file circularbuffer.h.

◆ getFreeElementsRead()

template<typename T>
int UTILSLIB::CircularBuffer< T >::getFreeElementsRead ( )
inline

Returns the number of free elements for thread safe reading.

Returns
Number of elements currently available to pop.

Definition at line 291 of file circularbuffer.h.

◆ getFreeElementsWrite()

template<typename T>
int UTILSLIB::CircularBuffer< T >::getFreeElementsWrite ( )
inline

Returns the number of free elements for thread safe reading.

Returns
Number of free slots currently available to push into.

Definition at line 299 of file circularbuffer.h.

◆ pause()

template<typename T>
void UTILSLIB::CircularBuffer< T >::pause ( bool bPause)
inline

Pauses the buffer. Skpis any incoming matrices and only pops zero matrices.

Parameters
[in]bPauseTrue to pause the buffer, false to resume it.

Definition at line 283 of file circularbuffer.h.

◆ pop()

template<typename T>
bool UTILSLIB::CircularBuffer< T >::pop ( T & element)
inline

Returns the first element (first in first out).

Parameters
[out]elementReceives the first element; left unchanged on failure.
Returns
True if an element was popped, false if the buffer is paused or empty within the timeout.

Definition at line 241 of file circularbuffer.h.

◆ push() [1/2]

template<typename T>
bool UTILSLIB::CircularBuffer< T >::push ( const T & newElement)
inline

Adds an element at the end of the buffer.

Parameters
[in]newElementpointer to an Array which should be apend to the end.
Returns
True if the element was written, false if the buffer is paused or no space freed up within the timeout.

Definition at line 222 of file circularbuffer.h.

◆ push() [2/2]

template<typename T>
bool UTILSLIB::CircularBuffer< T >::push ( const T * pArray,
unsigned int size )
inline

Adds a whole array at the end buffer.

Parameters
[in]pArraypointer to an Array which should be apend to the end.
[in]sizenumber of elements containing the array.
Returns
True if all elements were written, false if the buffer is paused or no space freed up within the timeout.

Definition at line 201 of file circularbuffer.h.


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