Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
SingleElementQueue< T > Class Template Reference

This class implements a queue which has at most 1 element (0 or 1). More...

#include <Concurrent.h>

Public Member Functions

bool isEmpty () const
 Note that although this api is thread safe, it will only report the state of the queue at the moment it is called.
bool pop (T &oElement)
 Returns the single element in the queue if there is one.
bool pop (T *oElement)
 Returns the single element in the queue if there is one.
void push (T const &iElement)
 Pushes one element in the queue.
void push (T const *iElement)
 Pushes one element in the queue.
 SingleElementQueue ()
 SingleElementQueue (std::unique_ptr< T > iFirstElement, bool iIsEmpty=false)
 This constructor can be used to add one element to the queue right away or when there is no empty constructor (required by the no argument constructor).

Private Attributes

bool fIsEmpty
std::unique_ptr< T > fSingleElement
SpinLock fSpinLock

Detailed Description

template<typename T>
class pongasoft::Utils::Concurrent::WithSpinLock::SingleElementQueue< T >

This class implements a queue which has at most 1 element (0 or 1).

If there is already an element and the push method is called again, it will replace the current element. This implementation uses a SpinLock and is thread safe to be called by any number of threads. This implementation does not allocate any memory and is expecting the T type to have an empty constructor and operator=.

Constructor & Destructor Documentation

◆ SingleElementQueue() [1/2]

template<typename T>
SingleElementQueue ( )
inline

◆ SingleElementQueue() [2/2]

template<typename T>
SingleElementQueue ( std::unique_ptr< T > iFirstElement,
bool iIsEmpty = false )
inlineexplicit

This constructor can be used to add one element to the queue right away or when there is no empty constructor (required by the no argument constructor).

Member Function Documentation

◆ isEmpty()

template<typename T>
bool isEmpty ( ) const
inline

Note that although this api is thread safe, it will only report the state of the queue at the moment it is called.

You should not assume that because isEmpty() returns false, then pop will return true!

Returns
true if the queue is empty

◆ pop() [1/2]

template<typename T>
bool pop ( T & oElement)
inline

Returns the single element in the queue if there is one.

Parameters
oElementthis will be populated with the value of the element in the queue or left untouched if there isn't one
Returns
true if there was one element in the queue, false otherwise

◆ pop() [2/2]

template<typename T>
bool pop ( T * oElement)
inline

Returns the single element in the queue if there is one.

Parameters
oElementthis will be populated with the value of the element in the queue or left untouched if there isn't one
Returns
true if there was one element in the queue, false otherwise

◆ push() [1/2]

template<typename T>
void push ( T const & iElement)
inline

Pushes one element in the queue.

If the queue already had an element it will be replaced.

Parameters
iElementthe element to push (clearly not modified by the call)

◆ push() [2/2]

template<typename T>
void push ( T const * iElement)
inline

Pushes one element in the queue.

If the queue already had an element it will be replaced.

Parameters
iElementthe element to push (clearly not modified by the call)

Member Data Documentation

◆ fIsEmpty

template<typename T>
bool fIsEmpty
private

◆ fSingleElement

template<typename T>
std::unique_ptr<T> fSingleElement
private

◆ fSpinLock

template<typename T>
SpinLock fSpinLock
mutableprivate

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