Jamba C++ API  4.1.0
SingleElementQueue< T > Class Template Reference

This is the lock free version of the SingleElementQueue. More...

#include <Concurrent.h>

Inherits SingleElementStorage< T >.

Public Member Functions

T const * last () const
 
void last (T &oElement) const
 Copy the last value that was popped to oElement. More...
 
T * pop ()
 
bool pop (T &oElement)
 Copy the popped value to oElement and return true when there is a new value otherwise do nothing and return false. More...
 
T const * popOrLast ()
 
void popOrLast (T &oElement)
 Copy either the new value (if there is one) or the last value that was popped to oElement. More...
 
void push (T const &iElement)
 Pushes (a copy of) iElement in the queue. More...
 
void push (T const *iElement)
 Pushes (a copy of) *iElement in the queue. More...
 
 SingleElementQueue ()
 
 SingleElementQueue (std::unique_ptr< T > iElement, bool iIsEmpty=false)
 This constructor should be used if T does not provide an empty constructor. More...
 
template<class ElementModifier >
void updateAndPush (ElementModifier const &iElementModifier)
 Use this flavor of push to avoid copy. More...
 
template<class ElementModifier >
bool updateAndPushIf (ElementModifier const &iElementModifier)
 Use this flavor of push to avoid copy. More...
 
- Public Member Functions inherited from SingleElementStorage< T >
bool __isLockFree () const
 Used (from test) to make sure that it is a lock free implementation. More...
 
bool isEmpty () const
 
 SingleElementStorage (std::unique_ptr< T > iElement, bool iIsEmpty) noexcept
 
 ~SingleElementStorage ()
 

Private Types

using Element = typename SingleElementStorage< T >::Element
 

Private Member Functions

void pushValue ()
 

Private Attributes

std::unique_ptr< ElementfPopValue
 
std::unique_ptr< ElementfPushValue
 

Additional Inherited Members

- Protected Member Functions inherited from SingleElementStorage< T >
std::unique_ptr< Element__newElement () const
 
std::unique_ptr< T > __newT () const
 
std::unique_ptr< Elementload (std::unique_ptr< Element > iElement)
 Loads an element from storage. More...
 
std::unique_ptr< Elementstore (std::unique_ptr< Element > iElement)
 Stores an element in the storage. More...
 

Detailed Description

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

This is the lock free version of the SingleElementQueue.

Internally it uses a different pointer for push and pop. As described in the comment for SingleElementStorage, all methods related to 'pop' can be called in one thread while all methods related to 'push' can be called by another.

Member Typedef Documentation

◆ Element

using Element = typename SingleElementStorage<T>::Element
private

Constructor & Destructor Documentation

◆ SingleElementQueue() [1/2]

SingleElementQueue ( )
inline

◆ SingleElementQueue() [2/2]

SingleElementQueue ( std::unique_ptr< T >  iElement,
bool  iIsEmpty = false 
)
inlineexplicit

This constructor should be used if T does not provide an empty constructor.

Member Function Documentation

◆ last() [1/2]

T const* last ( ) const
inline
Returns
returns the last value that was popped (never nullptr). Does NOT check for new value

◆ last() [2/2]

void last ( T &  oElement) const
inline

Copy the last value that was popped to oElement.

Does NOT check for new value

◆ pop() [1/2]

T* pop ( )
inline
Returns
the value popped or nullptr if nothing to pop

◆ pop() [2/2]

bool pop ( T &  oElement)
inline

Copy the popped value to oElement and return true when there is a new value otherwise do nothing and return false.

◆ popOrLast() [1/2]

T const* popOrLast ( )
inline
Returns
if there is a new value to pop, returns it otherwise return the last value that was popped (never nullptr)

◆ popOrLast() [2/2]

void popOrLast ( T &  oElement)
inline

Copy either the new value (if there is one) or the last value that was popped to oElement.

◆ push() [1/2]

void push ( T const &  iElement)
inline

Pushes (a copy of) iElement in the queue.

◆ push() [2/2]

void push ( T const *  iElement)
inline

Pushes (a copy of) *iElement in the queue.

◆ pushValue()

void pushValue ( )
inlineprivate

◆ updateAndPush()

void updateAndPush ( ElementModifier const &  iElementModifier)
inline

Use this flavor of push to avoid copy.

ElementModifier will be called back with the internal pointer to update it.

◆ updateAndPushIf()

bool updateAndPushIf ( ElementModifier const &  iElementModifier)
inline

Use this flavor of push to avoid copy.

ElementModifier will be called back with the internal pointer to update it. This flavor uses a callback that returns true when the push should happen and false otherwise.

Member Data Documentation

◆ fPopValue

std::unique_ptr<Element> fPopValue
private

◆ fPushValue

std::unique_ptr<Element> fPushValue
private

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