jaffarCommon
Loading...
Searching...
No Matches
Public Member Functions | List of all members
jaffarCommon::concurrent::Deque< T > Class Template Reference

#include <concurrent.hpp>

Public Member Functions

__JAFFAR_COMMON_INLINE__ auto & getInternalStorage ()
 
__JAFFAR_COMMON_INLINE__ void push_back_no_lock (T element)
 
__JAFFAR_COMMON_INLINE__ void push_back (T element)
 
__JAFFAR_COMMON_INLINE__ void push_front_no_lock (T element)
 
__JAFFAR_COMMON_INLINE__ void push_front (T element)
 
__JAFFAR_COMMON_INLINE__ T front () const
 
__JAFFAR_COMMON_INLINE__ T back () const
 
__JAFFAR_COMMON_INLINE__ void pop_front ()
 
__JAFFAR_COMMON_INLINE__ void pop_back ()
 
__JAFFAR_COMMON_INLINE__ bool pop_back_get (T &element)
 
__JAFFAR_COMMON_INLINE__ bool pop_front_get (T &element)
 
__JAFFAR_COMMON_INLINE__ size_t pop_front_get_batch (T *elements, const size_t maxCount)
 
__JAFFAR_COMMON_INLINE__ size_t wasSize () const
 

Detailed Description

template<class T>
class jaffarCommon::concurrent::Deque< T >

This implementation of a concurrent doble-ended queue class was created specifically for Jaffar's engine It allows for lock-free front and back push, pop, and pop_get operations It uses a single mutex to coordinate access. This could theoretically be improved, but for the time being seems to suffice

Member Function Documentation

◆ back()

template<class T >
__JAFFAR_COMMON_INLINE__ T jaffarCommon::concurrent::Deque< T >::back ( ) const
inline

Gets the element at the back of the Deque

Note
This is not a thread safe operation
This operation does not check for an empty container and might produce unexpected behaviour if ran with an empty container
Returns
The element at the back of the Deque

◆ front()

template<class T >
__JAFFAR_COMMON_INLINE__ T jaffarCommon::concurrent::Deque< T >::front ( ) const
inline

Gets the element at the front of the Deque

Note
This is not a thread safe operation
This operation does not check for an empty container and might produce unexpected behaviour if ran with an empty container
Returns
The element at the front of the Deque

◆ getInternalStorage()

template<class T >
__JAFFAR_COMMON_INLINE__ auto & jaffarCommon::concurrent::Deque< T >::getInternalStorage ( )
inline

Gets access to the internal Deque storage

Returns
A reference to the internal Deque storage

◆ pop_back()

template<class T >
__JAFFAR_COMMON_INLINE__ void jaffarCommon::concurrent::Deque< T >::pop_back ( )
inline

Pops (removes) the element at the back of the Deque

Note
This is a thread safe operation
This operation does not check for an empty container and might produce unexpected behaviour if ran with an empty container

◆ pop_back_get()

template<class T >
__JAFFAR_COMMON_INLINE__ bool jaffarCommon::concurrent::Deque< T >::pop_back_get ( T &  element)
inline

Pops (removes) the element at the back of the Deque and retrieves it

Note
This is a thread safe operation
Parameters
[out]elementA reference to the storage to save the element into
Returns
True, if the operation was successful; false, if the Deque was empty

◆ pop_front()

template<class T >
__JAFFAR_COMMON_INLINE__ void jaffarCommon::concurrent::Deque< T >::pop_front ( )
inline

Pops (removes) the element at the front of the Deque

Note
This is a thread safe operation
This operation does not check for an empty container and might produce unexpected behaviour if ran with an empty container

◆ pop_front_get()

template<class T >
__JAFFAR_COMMON_INLINE__ bool jaffarCommon::concurrent::Deque< T >::pop_front_get ( T &  element)
inline

Pops (removes) the element at the front of the Deque and retrieves it

Note
This is a thread safe operation
Parameters
[out]elementA reference to the storage to save the element into
Returns
True, if the operation was successful; false, if the Deque was empty

◆ pop_front_get_batch()

template<class T >
__JAFFAR_COMMON_INLINE__ size_t jaffarCommon::concurrent::Deque< T >::pop_front_get_batch ( T *  elements,
const size_t  maxCount 
)
inline

Pops (removes) up to maxCount elements from the front of the Deque under a single lock acquisition, copying them into the provided buffer in front-to-back order.

Note
This is a thread safe operation.

Batching amortizes the mutex cost across many elements. Under heavy multi-consumer contention (dozens of threads each pulling one element at a time, as the Jaffar engine does when the per-element work is cheap) the lock/unlock pair – not the pop itself – dominates wall time. Grabbing a run of elements per lock cuts lock-acquisition traffic by up to maxCount.

Parameters
[out]elementsDestination buffer; must have room for at least maxCount elements
[in]maxCountMaximum number of elements to pop
Returns
The number of elements actually popped (0 if the Deque was empty)

◆ push_back()

template<class T >
__JAFFAR_COMMON_INLINE__ void jaffarCommon::concurrent::Deque< T >::push_back ( element)
inline

Pushes an element to the back of the deque with locking protection

Note
This is a thread safe operation
Parameters
[in]elementThe input element to push

◆ push_back_no_lock()

template<class T >
__JAFFAR_COMMON_INLINE__ void jaffarCommon::concurrent::Deque< T >::push_back_no_lock ( element)
inline

Pushes an element to the back of the deque without any locking protection

Note
This is not a thread safe operation
Parameters
[in]elementThe input element to push

◆ push_front()

template<class T >
__JAFFAR_COMMON_INLINE__ void jaffarCommon::concurrent::Deque< T >::push_front ( element)
inline

Pushes an element to the front of the deque with locking protection

Note
This is a thread safe operation
Parameters
[in]elementThe input element to push

◆ push_front_no_lock()

template<class T >
__JAFFAR_COMMON_INLINE__ void jaffarCommon::concurrent::Deque< T >::push_front_no_lock ( element)
inline

Pushes an element to the front of the deque without any locking protection

Note
This is not a thread safe operation
Parameters
[in]elementThe input element to push

◆ wasSize()

template<class T >
__JAFFAR_COMMON_INLINE__ size_t jaffarCommon::concurrent::Deque< T >::wasSize ( ) const
inline

Retrieves the size of the container at the time of checking

Note
Reads an atomic counter rather than std::deque::size(), so it is safe to call concurrently with pushes/pops (the size may be momentarily stale, but it will not crash by walking deque internals that another thread is mutating).
Returns
The current size of the Deque at the time of checking

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