Jamba C++ API 7.5.0
Loading...
Searching...
No Matches
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.
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.
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.
void push (T const &iElement)
 Pushes (a copy of) iElement in the queue.
void push (T const *iElement)
 Pushes (a copy of) *iElement in the queue.
 SingleElementQueue ()
 SingleElementQueue (std::unique_ptr< T > iElement, bool iIsEmpty=false)
 This constructor should be used if T does not provide an empty constructor.
template<class ElementModifier>
void updateAndPush (ElementModifier const &iElementModifier)
 Use this flavor of push to avoid copy.
template<class ElementModifier>
bool updateAndPushIf (ElementModifier const &iElementModifier)
 Use this flavor of push to avoid copy.
Public Member Functions inherited from SingleElementStorage< T >
bool __isLockFree () const
 Used (from test) to make sure that it is a lock free implementation.
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.
std::unique_ptr< Elementstore (std::unique_ptr< Element > iElement)
 Stores an element in the storage.

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

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

Constructor & Destructor Documentation

◆ SingleElementQueue() [1/2]

template<typename T>
SingleElementQueue ( )
inline

◆ SingleElementQueue() [2/2]

template<typename T>
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]

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

◆ last() [2/2]

template<typename T>
void last ( T & oElement) const
inline

Copy the last value that was popped to oElement.

Does NOT check for new value

◆ pop() [1/2]

template<typename T>
T * pop ( )
inline
Returns
the value popped or nullptr if nothing to pop

◆ pop() [2/2]

template<typename T>
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]

template<typename T>
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]

template<typename T>
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]

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

Pushes (a copy of) iElement in the queue.

◆ push() [2/2]

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

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

◆ pushValue()

template<typename T>
void pushValue ( )
inlineprivate

◆ updateAndPush()

template<typename T>
template<class ElementModifier>
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()

template<typename T>
template<class ElementModifier>
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

template<typename T>
std::unique_ptr<Element> fPopValue
private

◆ fPushValue

template<typename T>
std::unique_ptr<Element> fPushValue
private

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