MySQL 8.3.0
Source Code Documentation
container::Integrals_lockfree_queue< T, Null, Erased, I, A > Class Template Reference

Lock-free, fixed-size bounded, multiple-producer (MP), multiple-consumer (MC), circular FIFO queue for integral elements. More...

#include <integrals_lockfree_queue.h>

Classes

class  Iterator
 Iterator helper class to iterate over the queue staring at the virtual index pointed to by the head, up until the virtual index pointed to by the tail. More...
 

Public Types

enum class  enum_queue_state : short { SUCCESS = 0 , NO_MORE_ELEMENTS = -1 , NO_SPACE_AVAILABLE = -2 }
 
using pointer_type = T *
 
using const_pointer_type = T const *
 
using reference_type = T &
 
using const_reference_type = T const &
 
using value_type = T
 
using const_value_type = T const
 
using element_type = std::atomic< T >
 
using index_type = unsigned long long
 
using array_type = container::Atomics_array< T, I, A >
 
using atomic_type = memory::Aligned_atomic< index_type >
 

Public Member Functions

template<typename D = T, T M = Null, T F = Erased, typename J = I, typename B = A, std::enable_if_t<!std::is_same< B, std::nullptr_t >::value > * = nullptr>
 Integrals_lockfree_queue (A &alloc, size_t size)
 Constructor allowing a specific memory allocator and a specific queue capacity. More...
 
template<typename D = T, T M = Null, T F = Erased, typename J = I, typename B = A, std::enable_if_t< std::is_same< B, std::nullptr_t >::value > * = nullptr>
 Integrals_lockfree_queue (size_t size)
 Constructor allowing specific queue capacity. More...
 
 Integrals_lockfree_queue (Integrals_lockfree_queue< T, Null, Erased, I, A > const &rhs)=delete
 
 Integrals_lockfree_queue (Integrals_lockfree_queue< T, Null, Erased, I, A > &&rhs)=delete
 
virtual ~Integrals_lockfree_queue ()=default
 Destructor for the class. More...
 
Integrals_lockfree_queue< T, Null, Erased, I, A > & operator= (Integrals_lockfree_queue< T, Null, Erased, I, A > const &rhs)=delete
 
Integrals_lockfree_queue< T, Null, Erased, I, A > & operator= (Integrals_lockfree_queue< T, Null, Erased, I, A > &&rhs)=delete
 
array_typearray ()
 Returns the underlying instance of memory::Atomics_array which holds the allocated memory for the array of std::atomic<T> elements. More...
 
void clear ()
 Sets all queue positions to Null and points the head and tail of the queue to the 0 virtual index. More...
 
bool is_empty () const
 Retrieves whether or not the head and tail of the queue are pointing to the same virtual index. More...
 
bool is_full () const
 Retrieves whether or not the tail of the queue is pointing to the same virtual index as the computed by adding the queue capacity() to the virtual index pointed to by the head of the queue. More...
 
index_type head () const
 Retrieves the virtual index that the head of the queue is pointing to. More...
 
index_type tail () const
 Retrieves the virtual index that the tail of the queue is pointing to. More...
 
value_type front () const
 Retrieves the element at the front of the queue, i.e. More...
 
value_type back () const
 Retrieves the value of the position at the back of the queue, i.e. More...
 
Integrals_lockfree_queue< T, Null, Erased, I, A > & operator>> (reference_type out)
 Retrieves the value at the virtual index pointed by the head of the queue, clears that position, updates the virtual index stored in the head and clears the value returned by get_state(), setting it to SUCCESS. More...
 
Integrals_lockfree_queue< T, Null, Erased, I, A > & operator<< (const_reference_type to_push)
 Takes the value passed on as a parameter, stores it in the virtual index pointed to by the tail of the queue, updates the virtual index stored in the tail and clears the value returned by get_state(), setting it to SUCCESS. More...
 
value_type pop ()
 Retrieves the value at the virtual index pointed by the head of the queue, clears that position, updates the virtual index stored in the head and clears the value returned by get_state(), setting it to SUCCESS. More...
 
Integrals_lockfree_queue< T, Null, Erased, I, A > & push (value_type to_push)
 Takes the value passed on as a parameter, stores it in the virtual index pointed to by the tail of the queue, updates the virtual index stored in the tail and clears the value returned by get_state(), setting it to SUCCESS. More...
 
Iterator begin () const
 Retrieves an iterator instance that points to the same position pointed by the head of the queue. More...
 
Iterator end () const
 Retrieves an iterator instance that points to the same position pointed by the tail of the queue. More...
 
template<typename D = T, T M = Null, T F = Erased, typename J = I, typename B = A, typename Pred , std::enable_if_t< M !=F > * = nullptr>
size_t erase_if (Pred predicate)
 Erases values from the queue. More...
 
size_t capacity () const
 Returns the maximum number of elements allowed to coexist in the queue. More...
 
size_t allocated_size () const
 Returns the amount of bytes needed to store the maximum number of elements allowed to coexist in the queue. More...
 
Integrals_lockfree_queue< T, Null, Erased, I, A > & clear_state ()
 Clears the error state of the last performed operations, if any. More...
 
enum_queue_state get_state () const
 Retrieves the error/success state of the last performed operation. More...
 
std::string to_string () const
 Return this queue textual representation. More...
 

Static Public Attributes

static constexpr T null_value = Null
 
static constexpr T erased_value = Erased
 
static constexpr index_type set_bit = 1ULL << 63
 
static constexpr index_type clear_bit = set_bit - 1
 

Private Member Functions

size_t translate (index_type from) const
 Translates a virtual monotonically increasing index into an index bounded to the queue capacity. More...
 
enum_queue_statestate () const
 Retrieves the thread storage duration operation state variable. More...
 

Private Attributes

size_t m_capacity {0}
 The maximum allowed number of element allowed to coexist in the queue. More...
 
array_type m_array
 The array of atomics in which the elements will be stored. More...
 
atomic_type m_head {0}
 The virtual index being pointed to by the head of the queue. More...
 
atomic_type m_tail {0}
 The virtual index being pointed to by the tail of the queue. More...
 

Friends

std::ostream & operator<< (std::ostream &out, Integrals_lockfree_queue< T, Null, Erased, I, A > const &in)
 

Detailed Description

template<typename T, T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
class container::Integrals_lockfree_queue< T, Null, Erased, I, A >

Lock-free, fixed-size bounded, multiple-producer (MP), multiple-consumer (MC), circular FIFO queue for integral elements.

Monotonically ever increasing virtual indexes are used to keep track of the head and tail pointer for the size-bounded circular queue. Virtual indexes are translated into memory indexes by calculating the remainder of the integer division of the virtual index by the queue capacity. The maximum value of a virtual index is 2^63 - 1.

Head is the pointer to the virtual index of the first position that holds an element to be popped, if any.

Tail is the pointer to the virtual index of the first available position to push an element to, if any.

Template parameters are as follows:

  • T: The integral type for the queue elements.
  • Null: Value of type T, that will be used to mark a queue position as empty.
  • Erased: Value of type T, that will be used to mark an queue position as erased.
  • I: Type of indexing to be used by the underlying array in the form of a class. Available classes are container::Padded_indexing and container::Interleaved_indexing, check the classes documentation for further details. The parameter defaults to container::Padded_indexing.
  • A: Type of memory allocator to be used, in the form of a class (defaults to no allocator).

All the available operations are thread-safe, in the strict sense of no memory problems rise from multiple threads trying to perform operations concurrently.

However, being a lock-free structure, the queue may be changing at the same time as operations access both pointers and values or a client of the API evaluates the result of the invoked operation. The operation results and returning states are always based on the thread local view of the queue state, which may be safe or unsafe to proceed with the given operation. Therefore, extra validations, client-side serialization and/or retry mechanisms may be needed while using the queue operations.

Available methods are:

  • pop: if the head of the queue points to a virtual index different from the one pointed by the tail of the queue, removes the element pointed to by the head of the queue, points the head to the next virtual index and returns the retrieved value. If head and tail of the queue point to the same virtual index, the queue is empty, Null is returned and the thread operation state is set to NO_MORE_ELEMENTS.
  • push: if the tail of the queue points to a virtual index different from the one pointed by head-plus-queue-capacity, sets the position pointed by tail with the provided element and points the tail to the next virtual index. If tail and head plus queue capacity point to the same virtual index, the queue is full, no operation is performed and the thread operation state is set to NO_SPACE_AVAILABLE.
  • capacity: maximum number of elements allowed to coexist in the queue.
  • head: pointer to the virtual index of the first available element, if any.
  • tail: pointer to the virtual index of the first available position to add an element to. Additionally, the value returned by tail() can also give an lower-than approximation of the total amount of elements already pushed into the queue -in between reading the virtual index tail is pointing to and evaluating it, some more elements may have been pushed.
  • front: the first available element. If none, Null is returned.
  • back: the last available element. If none, Null is returned.
  • clear: sets all positions of the underlying array to Null and resets the virtual index pointed to by both the head and the tail of the queue to 0.
  • is_empty: whether or not the head and tail of the queue point to the same virtual index.
  • is_full: whether or not the tail and head-plus-queue-capacity point to the same virtual index.
  • erase_if: traverses the queue, starting at the queue relative memory index 0, stopping at the relative memory index capacity() - 1 and invoking the passed-on predicate over each position value, while disregarding positions that have Null or Erased values.

Note that, if Null and Erased hold the same value, the resulting class will not include the erase_if method.

Member Typedef Documentation

◆ array_type

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
using container::Integrals_lockfree_queue< T, Null, Erased, I, A >::array_type = container::Atomics_array<T, I, A>

◆ atomic_type

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
using container::Integrals_lockfree_queue< T, Null, Erased, I, A >::atomic_type = memory::Aligned_atomic<index_type>

◆ const_pointer_type

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
using container::Integrals_lockfree_queue< T, Null, Erased, I, A >::const_pointer_type = T const *

◆ const_reference_type

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
using container::Integrals_lockfree_queue< T, Null, Erased, I, A >::const_reference_type = T const &

◆ const_value_type

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
using container::Integrals_lockfree_queue< T, Null, Erased, I, A >::const_value_type = T const

◆ element_type

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
using container::Integrals_lockfree_queue< T, Null, Erased, I, A >::element_type = std::atomic<T>

◆ index_type

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
using container::Integrals_lockfree_queue< T, Null, Erased, I, A >::index_type = unsigned long long

◆ pointer_type

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
using container::Integrals_lockfree_queue< T, Null, Erased, I, A >::pointer_type = T *

◆ reference_type

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
using container::Integrals_lockfree_queue< T, Null, Erased, I, A >::reference_type = T &

◆ value_type

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
using container::Integrals_lockfree_queue< T, Null, Erased, I, A >::value_type = T

Member Enumeration Documentation

◆ enum_queue_state

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
enum class container::Integrals_lockfree_queue::enum_queue_state : short
strong
Enumerator
SUCCESS 
NO_MORE_ELEMENTS 
NO_SPACE_AVAILABLE 

Constructor & Destructor Documentation

◆ Integrals_lockfree_queue() [1/4]

template<typename T , T Null, T Erased, typename I , typename A >
template<typename D , T M, T F, typename J , typename B , std::enable_if_t<!std::is_same< B, std::nullptr_t >::value > * >
container::Integrals_lockfree_queue< T, Null, Erased, I, A >::Integrals_lockfree_queue ( A &  alloc,
size_t  size 
)

Constructor allowing a specific memory allocator and a specific queue capacity.

The queue allocated memory may differ from capacity() * sizeof(T) since additional space may be required to prevent false sharing between threads.

Parameters
allocThe memory allocator instance
sizeThe queue maximum capacity

◆ Integrals_lockfree_queue() [2/4]

template<typename T , T Null, T Erased, typename I , typename A >
template<typename D , T M, T F, typename J , typename B , std::enable_if_t< std::is_same< B, std::nullptr_t >::value > * >
container::Integrals_lockfree_queue< T, Null, Erased, I, A >::Integrals_lockfree_queue ( size_t  size)

Constructor allowing specific queue capacity.

The queue allocated memory may differ from capacity() * sizeof(T) since additional space may be required to prevent false sharing between threads.

Parameters
sizeThe queue maximum capacity

◆ Integrals_lockfree_queue() [3/4]

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
container::Integrals_lockfree_queue< T, Null, Erased, I, A >::Integrals_lockfree_queue ( Integrals_lockfree_queue< T, Null, Erased, I, A > const &  rhs)
delete

◆ Integrals_lockfree_queue() [4/4]

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
container::Integrals_lockfree_queue< T, Null, Erased, I, A >::Integrals_lockfree_queue ( Integrals_lockfree_queue< T, Null, Erased, I, A > &&  rhs)
delete

◆ ~Integrals_lockfree_queue()

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
virtual container::Integrals_lockfree_queue< T, Null, Erased, I, A >::~Integrals_lockfree_queue ( )
virtualdefault

Destructor for the class.

Member Function Documentation

◆ allocated_size()

template<typename T , T Null, T Erased, typename I , typename A >
size_t container::Integrals_lockfree_queue< T, Null, Erased, I, A >::allocated_size

Returns the amount of bytes needed to store the maximum number of elements allowed to coexist in the queue.

Returns
the amount of bytes needed to store the maximum number of elements allowed to coexist in th queue

◆ array()

template<typename T , T Null, T Erased, typename I , typename A >
container::Integrals_lockfree_queue< T, Null, Erased, I, A >::array_type & container::Integrals_lockfree_queue< T, Null, Erased, I, A >::array

Returns the underlying instance of memory::Atomics_array which holds the allocated memory for the array of std::atomic<T> elements.

Returns
the underlying instance of memory::Atomics_array

◆ back()

template<typename T , T Null, T Erased, typename I , typename A >
container::Integrals_lockfree_queue< T, Null, Erased, I, A >::value_type container::Integrals_lockfree_queue< T, Null, Erased, I, A >::back

Retrieves the value of the position at the back of the queue, i.e.

the value stored in the virtual index just prior to the virtual index pointed to by the tail of the queue.

The returned value may be Null or Erased, whatever value that is held by the given virtual index position.

As this method is an alias for array()[tail()], the queue may be changed concurrently and it is possible for this method to return a value assigned to a position outside the bounds of the head and tail of the queue (between thread-local fetch of the tail pointer and the access to the position indexed by the local value, operations moved the head to a virtual index higher than the locally stored). This means that Null may be returned or that a value that is currently being popped may be returned.

Returns
the element at the back of the queue

◆ begin()

template<typename T , T Null, T Erased, typename I , typename A >
container::Integrals_lockfree_queue< T, Null, Erased, I, A >::Iterator container::Integrals_lockfree_queue< T, Null, Erased, I, A >::begin ( void  ) const

Retrieves an iterator instance that points to the same position pointed by the head of the queue.

Please, be aware that, while using standard library features that use the Iterator requirement, like for_each loops, std::find, std::find_if, etc:

  • The iterator may point to Null values at the beginning of the iteration because elements were popped just after the queue begin() method is invoked, the moment when the iterator pointing to the same virtual index as the head of the queue is computed.
Returns
An instance of an iterator instance that points to virtual index pointed by the head of the queue

◆ capacity()

template<typename T , T Null, T Erased, typename I , typename A >
size_t container::Integrals_lockfree_queue< T, Null, Erased, I, A >::capacity

Returns the maximum number of elements allowed to coexist in the queue.

Returns
The maximum number of elements allowed to coexist in the queue

◆ clear()

template<typename T , T Null, T Erased, typename I , typename A >
void container::Integrals_lockfree_queue< T, Null, Erased, I, A >::clear

Sets all queue positions to Null and points the head and tail of the queue to the 0 virtual index.

◆ clear_state()

template<typename T , T Null, T Erased, typename I , typename A >
container::Integrals_lockfree_queue< T, Null, Erased, I, A > & container::Integrals_lockfree_queue< T, Null, Erased, I, A >::clear_state

Clears the error state of the last performed operations, if any.

The operation state is a thread storage duration variable, making it a per-thread state.

Returns
The reference to this object, for chaining purposes.

◆ end()

template<typename T , T Null, T Erased, typename I , typename A >
container::Integrals_lockfree_queue< T, Null, Erased, I, A >::Iterator container::Integrals_lockfree_queue< T, Null, Erased, I, A >::end ( void  ) const

Retrieves an iterator instance that points to the same position pointed by the tail of the queue.

Please, be aware that, while using standard library features that use the Iterator requirement, like for_each loops, std::find, std::find_if, etc:

  • The iteration may never stop because there is always an element being pushed before the queue end() method is invoked, the moment when the iterator pointing to the same virtual index has the tail of the queue is computed.
Returns
An instance of an iterator instance that points to virtual index pointed by the tail of the queue

◆ erase_if()

template<typename T , T Null, T Erased, typename I , typename A >
template<typename D , T M, T F, typename J , typename B , typename Pred , std::enable_if_t< M !=F > * >
size_t container::Integrals_lockfree_queue< T, Null, Erased, I, A >::erase_if ( Pred  predicate)

Erases values from the queue.

The traversing is linear and not in between the virtual indexes pointed to by the head and the tail of the queue but rather between 0 and Integrals_lockfree_queue::capacity() - 1.

An element may be conditionally erased according to the evaluation of the predicate predicate which should be any predicate which is translatable to [](value_type value) -> bool. If the predicate evaluates to true, the value is replace by Erased.

If both Null and Erased evaluate to the same value, this method will not be available after the template substitutions since erased values must be identifiable by the pop and push operations.

Check C++ documentation for the definition of Predicate named requirement for more information.

Parameters
predicateThe predicate invoked upon a given queue position and if evaluated to true will force the removal of such element.
Returns
The number of values erased.

◆ front()

template<typename T , T Null, T Erased, typename I , typename A >
container::Integrals_lockfree_queue< T, Null, Erased, I, A >::value_type container::Integrals_lockfree_queue< T, Null, Erased, I, A >::front

Retrieves the element at the front of the queue, i.e.

the value stored in the virtual index pointed to by the head of the queue.

The returned value may be Null, Erased or whatever value that is held by the given virtual index position at the moment it's accessed.

As this method is an alias for array()[head()], the queue may be changed concurrently and, because it is a circular queue, it is possible for this method to return a value that has not been popped yet and it will not be popped in the next call for pop() (the circular queue logic made the tail to wrap and overlap the thread local value of head).

Returns
the element at the front of the queue

◆ get_state()

template<typename T , T Null, T Erased, typename I , typename A >
container::Integrals_lockfree_queue< T, Null, Erased, I, A >::enum_queue_state container::Integrals_lockfree_queue< T, Null, Erased, I, A >::get_state

Retrieves the error/success state of the last performed operation.

The operation state is a thread storage duration variable, making it a per-thread state.

Possible values are:

  • SUCCESS if the operation was successful
  • NO_MORE_ELEMENTS if there are no more elements to pop
  • NO_SPACE_AVAILABLE if there is no more room for pushing elements

State may be changed by any of the pop, push operations.

Returns
the error/success state of the invoking thread last operation.

◆ head()

template<typename T , T Null, T Erased, typename I , typename A >
container::Integrals_lockfree_queue< T, Null, Erased, I, A >::index_type container::Integrals_lockfree_queue< T, Null, Erased, I, A >::head

Retrieves the virtual index that the head of the queue is pointing to.

Returns
the virtual index the head of the queue is pointing to

◆ is_empty()

template<typename T , T Null, T Erased, typename I , typename A >
bool container::Integrals_lockfree_queue< T, Null, Erased, I, A >::is_empty

Retrieves whether or not the head and tail of the queue are pointing to the same virtual index.

No evaluation of the value held in the given position is made. If, for instance, head and tail point to consecutive virtual indexes and the value stored in the position pointed to by head is Erased, is_empty will return false and pop will return Null and trigger a NO_MORE_ELEMENTS state change.

Returns
true if there aren't more elements to be popped, false otherwise

◆ is_full()

template<typename T , T Null, T Erased, typename I , typename A >
bool container::Integrals_lockfree_queue< T, Null, Erased, I, A >::is_full

Retrieves whether or not the tail of the queue is pointing to the same virtual index as the computed by adding the queue capacity() to the virtual index pointed to by the head of the queue.

No evaluation of the value held in the given position is made. If, for instance, all the values stored in the positions between head and tail are Erased, is_full will return true and pop will return Null and trigger a NO_MORE_ELEMENTS state change.

Returns
true if there isn't space for more elements to be pushed, false otherwise

◆ operator<<()

template<typename T , T Null, T Erased, typename I , typename A >
container::Integrals_lockfree_queue< T, Null, Erased, I, A > & container::Integrals_lockfree_queue< T, Null, Erased, I, A >::operator<< ( const_reference_type  to_push)

Takes the value passed on as a parameter, stores it in the virtual index pointed to by the tail of the queue, updates the virtual index stored in the tail and clears the value returned by get_state(), setting it to SUCCESS.

If the tail of the queue points to a virtual index that has already an element assigned (queue is full), the operation fails and the value returned by get_state() is NO_SPACE AVAILABLE.

Parameters
to_pushThe value to push into the queue.
Returns
The reference to this object, for chaining purposes.

◆ operator=() [1/2]

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
Integrals_lockfree_queue< T, Null, Erased, I, A > & container::Integrals_lockfree_queue< T, Null, Erased, I, A >::operator= ( Integrals_lockfree_queue< T, Null, Erased, I, A > &&  rhs)
delete

◆ operator=() [2/2]

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
Integrals_lockfree_queue< T, Null, Erased, I, A > & container::Integrals_lockfree_queue< T, Null, Erased, I, A >::operator= ( Integrals_lockfree_queue< T, Null, Erased, I, A > const &  rhs)
delete

◆ operator>>()

template<typename T , T Null, T Erased, typename I , typename A >
container::Integrals_lockfree_queue< T, Null, Erased, I, A > & container::Integrals_lockfree_queue< T, Null, Erased, I, A >::operator>> ( reference_type  out)

Retrieves the value at the virtual index pointed by the head of the queue, clears that position, updates the virtual index stored in the head and clears the value returned by get_state(), setting it to SUCCESS.

If the head of the queue points to a virtual index that has no element assigned (queue is empty), the operation fails, Null is stored in the out parameter and the value returned by get_state() is NO_MORE_ELEMENTS.

Parameters
outThe variable reference to store the value in.
Returns
The reference to this object, for chaining purposes.

◆ pop()

template<typename T , T Null, T Erased, typename I , typename A >
T container::Integrals_lockfree_queue< T, Null, Erased, I, A >::pop

Retrieves the value at the virtual index pointed by the head of the queue, clears that position, updates the virtual index stored in the head and clears the value returned by get_state(), setting it to SUCCESS.

If the head of the queue points to a virtual index that has no element assigned yet (queue is empty), the operation returns Null and the value returned by get_state() is NO_MORE_ELEMENTS.

Returns
The value retrieved from the queue or Null if no element is available for popping

◆ push()

template<typename T , T Null, T Erased, typename I , typename A >
container::Integrals_lockfree_queue< T, Null, Erased, I, A > & container::Integrals_lockfree_queue< T, Null, Erased, I, A >::push ( value_type  to_push)

Takes the value passed on as a parameter, stores it in the virtual index pointed to by the tail of the queue, updates the virtual index stored in the tail and clears the value returned by get_state(), setting it to SUCCESS.

If the tail of the queue points to a virtual index that has already an element assigned (queue is full), the operation fails and the value returned by get_state() is NO_SPACE AVAILABLE.

Parameters
to_pushThe value to push into the queue.
Returns
The reference to this object, for chaining purposes.

◆ state()

template<typename T , T Null, T Erased, typename I , typename A >
container::Integrals_lockfree_queue< T, Null, Erased, I, A >::enum_queue_state & container::Integrals_lockfree_queue< T, Null, Erased, I, A >::state
private

Retrieves the thread storage duration operation state variable.

◆ tail()

template<typename T , T Null, T Erased, typename I , typename A >
container::Integrals_lockfree_queue< T, Null, Erased, I, A >::index_type container::Integrals_lockfree_queue< T, Null, Erased, I, A >::tail

Retrieves the virtual index that the tail of the queue is pointing to.

Returns
the virtual index the tail of the queue is pointing to

◆ to_string()

template<typename T , T Null, T Erased, typename I , typename A >
std::string container::Integrals_lockfree_queue< T, Null, Erased, I, A >::to_string

Return this queue textual representation.

Returns
the textual representation for this queue.

◆ translate()

template<typename T , T Null, T Erased, typename I , typename A >
size_t container::Integrals_lockfree_queue< T, Null, Erased, I, A >::translate ( index_type  from) const
private

Translates a virtual monotonically increasing index into an index bounded to the queue capacity.

Friends And Related Function Documentation

◆ operator<<

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
std::ostream & operator<< ( std::ostream &  out,
Integrals_lockfree_queue< T, Null, Erased, I, A > const &  in 
)
friend

Member Data Documentation

◆ clear_bit

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
constexpr index_type container::Integrals_lockfree_queue< T, Null, Erased, I, A >::clear_bit = set_bit - 1
staticconstexpr

◆ erased_value

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
constexpr T container::Integrals_lockfree_queue< T, Null, Erased, I, A >::erased_value = Erased
staticconstexpr

◆ m_array

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
array_type container::Integrals_lockfree_queue< T, Null, Erased, I, A >::m_array
private

The array of atomics in which the elements will be stored.

◆ m_capacity

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
size_t container::Integrals_lockfree_queue< T, Null, Erased, I, A >::m_capacity {0}
private

The maximum allowed number of element allowed to coexist in the queue.

◆ m_head

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
atomic_type container::Integrals_lockfree_queue< T, Null, Erased, I, A >::m_head {0}
private

The virtual index being pointed to by the head of the queue.

◆ m_tail

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
atomic_type container::Integrals_lockfree_queue< T, Null, Erased, I, A >::m_tail {0}
private

The virtual index being pointed to by the tail of the queue.

◆ null_value

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
constexpr T container::Integrals_lockfree_queue< T, Null, Erased, I, A >::null_value = Null
staticconstexpr

◆ set_bit

template<typename T , T Null = std::numeric_limits<T>::max(), T Erased = Null, typename I = container::Padded_indexing<T>, typename A = std::nullptr_t>
constexpr index_type container::Integrals_lockfree_queue< T, Null, Erased, I, A >::set_bit = 1ULL << 63
staticconstexpr

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