xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::lockFree::Queue< Element, Allocator > Class Template Referencefinal

A lock free queue. More...

#include <xentara/utils/lockFree/Queue.hpp>

Public Types

using value_type = Element
 The element type.
 
using allocator_type = Allocator
 The Allocator type.
 
using size_type = typename std::allocator_traits< Allocator >::size_type
 The type used for sizes.
 
using difference_type = typename std::allocator_traits< Allocator >::difference_type
 The type used for distances.
 
using reference = value_type &
 A reference to an element.
 
using const_reference = const value_type &
 A const reference to an element.
 
using pointer = typename std::allocator_traits< Allocator >::pointer
 A pointer to an element.
 
using const_pointer = typename std::allocator_traits< Allocator >::const_pointer
 A const pointer to an element.
 

Public Member Functions

constexpr Queue () noexcept(noexcept(Allocator()))=default
 Default constructor.
 
constexpr Queue (const Allocator &allocator) noexcept
 Constructor that sets the allocator.
 
 Queue (size_type capacity)
 Constructor for a queue that can hold a specific number of elements.
 
 Queue (size_type capacity, const Allocator &allocator)
 Constructor for a queue that can hold a specific number of elements.
 
template<typename... Arguments>
auto emplace (Arguments &&...arguments) noexcept(std::is_nothrow_constructible_v< Element, Arguments &&... >) -> bool
 Push an Element onto the queue.
 
auto push (const Element &element) noexcept(std::is_nothrow_copy_constructible_v< Element >) -> bool
 Push an element onto the queue without any arguments.
 
auto push (Element &&element) noexcept(std::is_nothrow_move_constructible_v< Element >) -> bool
 Move an element onto the queue without any arguments.
 
auto pop () noexcept(std::is_nothrow_move_constructible_v< Element >) -> std::optional< Element >
 Pop an element in an optional wrapper from the queue.
 
auto clear () -> void
 Clears the queue.
 
auto reset (size_type capacity) -> void
 Reset the queue to the given capacity.
 
constexpr auto capacity () const noexcept -> size_type
 Gets the maximum number of elements the queue can hold.
 
constexpr auto max_size () const noexcept -> size_type
 Gets the maximum possible capacity.
 

Detailed Description

template<typename Element, typename Allocator = std::allocator<Element>>
class xentara::utils::lockFree::Queue< Element, Allocator >

A lock free queue.

Template Parameters
ElementThe element type
Allocatorthe allocator for the element type

Member Typedef Documentation

◆ allocator_type

template<typename Element , typename Allocator = std::allocator<Element>>
using xentara::utils::lockFree::Queue< Element, Allocator >::allocator_type = Allocator

The Allocator type.

◆ const_pointer

template<typename Element , typename Allocator = std::allocator<Element>>
using xentara::utils::lockFree::Queue< Element, Allocator >::const_pointer = typename std::allocator_traits<Allocator>::const_pointer

A const pointer to an element.

◆ const_reference

template<typename Element , typename Allocator = std::allocator<Element>>
using xentara::utils::lockFree::Queue< Element, Allocator >::const_reference = const value_type &

A const reference to an element.

◆ difference_type

template<typename Element , typename Allocator = std::allocator<Element>>
using xentara::utils::lockFree::Queue< Element, Allocator >::difference_type = typename std::allocator_traits<Allocator>::difference_type

The type used for distances.

◆ pointer

template<typename Element , typename Allocator = std::allocator<Element>>
using xentara::utils::lockFree::Queue< Element, Allocator >::pointer = typename std::allocator_traits<Allocator>::pointer

A pointer to an element.

◆ reference

template<typename Element , typename Allocator = std::allocator<Element>>
using xentara::utils::lockFree::Queue< Element, Allocator >::reference = value_type &

A reference to an element.

◆ size_type

template<typename Element , typename Allocator = std::allocator<Element>>
using xentara::utils::lockFree::Queue< Element, Allocator >::size_type = typename std::allocator_traits<Allocator>::size_type

The type used for sizes.

◆ value_type

template<typename Element , typename Allocator = std::allocator<Element>>
using xentara::utils::lockFree::Queue< Element, Allocator >::value_type = Element

The element type.

Constructor & Destructor Documentation

◆ Queue() [1/4]

template<typename Element , typename Allocator = std::allocator<Element>>
constexpr xentara::utils::lockFree::Queue< Element, Allocator >::Queue ( )
constexprdefaultnoexcept

Default constructor.

Constructs an empty queue with a default constructed allocator.

A queue created with this constructor has a capacity of 0 and cannot hold any elements. You must make room for the elements using reset() before inserting any elements.

◆ Queue() [2/4]

template<typename Element , typename Allocator = std::allocator<Element>>
constexpr xentara::utils::lockFree::Queue< Element, Allocator >::Queue ( const Allocator &  allocator)
explicitconstexprnoexcept

Constructor that sets the allocator.

A queue created with this constructor has a capacity of 0 and cannot hold any elements. You must make room for the elements using reset() before inserting any elements.

Parameters
allocatorThe allocator

◆ Queue() [3/4]

template<typename Element , typename Allocator = std::allocator<Element>>
xentara::utils::lockFree::Queue< Element, Allocator >::Queue ( size_type  capacity)
explicit

Constructor for a queue that can hold a specific number of elements.

Parameters
capacityThe number of entries to create room for

◆ Queue() [4/4]

template<typename Element , typename Allocator = std::allocator<Element>>
xentara::utils::lockFree::Queue< Element, Allocator >::Queue ( size_type  capacity,
const Allocator &  allocator 
)
explicit

Constructor for a queue that can hold a specific number of elements.

Parameters
capacityThe number of entries to create room for
allocatorThe allocator

Member Function Documentation

◆ capacity()

template<typename Element , typename Allocator = std::allocator<Element>>
constexpr auto xentara::utils::lockFree::Queue< Element, Allocator >::capacity ( ) const -> size_type
constexprnoexcept

Gets the maximum number of elements the queue can hold.

Returns
the capacity of the queue

◆ clear()

template<typename Element , typename Allocator = std::allocator<Element>>
auto xentara::utils::lockFree::Queue< Element, Allocator >::clear ( ) -> void

Clears the queue.

Any current elements in the queue are deleted

Attention
This function is unsynchronized and must not be called while other threads are accessing the queue

◆ emplace()

template<typename Element , typename Allocator = std::allocator<Element>>
template<typename... Arguments>
auto xentara::utils::lockFree::Queue< Element, Allocator >::emplace ( Arguments &&...  arguments) -> bool
noexcept

Push an Element onto the queue.

Parameters
argumentsthe arguments to use to construct the element
Returns
returns true if element pushed on queue and false if it failed due to queue being full

◆ max_size()

template<typename Element , typename Allocator = std::allocator<Element>>
constexpr auto xentara::utils::lockFree::Queue< Element, Allocator >::max_size ( ) const -> size_type
constexprnoexcept

Gets the maximum possible capacity.

Returns
The maximum capacity that can be specified

◆ pop()

template<typename Element , typename Allocator = std::allocator<Element>>
auto xentara::utils::lockFree::Queue< Element, Allocator >::pop ( ) -> std::optional<Element>
noexcept

Pop an element in an optional wrapper from the queue.

Note
If the move constructor of the object throws an exception, the object is removed from the queue and destroyed silently. The exception is then rethrown.
Returns
returns the popped element in the optional wrapper or std::nullopt if the queue was empty

◆ push() [1/2]

template<typename Element , typename Allocator = std::allocator<Element>>
auto xentara::utils::lockFree::Queue< Element, Allocator >::push ( const Element &  element) -> bool
noexcept

Push an element onto the queue without any arguments.

Parameters
elementthe element to push onto the queue
Returns
returns true if element pushed on queue and false if it failed due to queue being full

◆ push() [2/2]

template<typename Element , typename Allocator = std::allocator<Element>>
auto xentara::utils::lockFree::Queue< Element, Allocator >::push ( Element &&  element) -> bool
noexcept

Move an element onto the queue without any arguments.

Parameters
elementthe element to move onto the queue
Returns
returns true if element pushed on queue and false if it failed due to queue being full

◆ reset()

template<typename Element , typename Allocator = std::allocator<Element>>
auto xentara::utils::lockFree::Queue< Element, Allocator >::reset ( size_type  capacity) -> void

Reset the queue to the given capacity.

Any current elements in the queue are deleted

Attention
This function is unsynchronized and must not be called while other threads are accessing the queue
Parameters
capacityThe number of entries to create room for