density
C++11 library for paged memory management, function queues, heterogeneous queues and lifo memory management
|
#include <conc_heter_queue.h>
Classes | |
class | consume_operation |
class | put_transaction |
class | reentrant_consume_operation |
class | reentrant_put_transaction |
Public Member Functions | |
constexpr | conc_heter_queue () noexcept=default |
constexpr | conc_heter_queue (const ALLOCATOR_TYPE &i_source_allocator) noexcept |
constexpr | conc_heter_queue (ALLOCATOR_TYPE &&i_source_allocator) noexcept |
conc_heter_queue (conc_heter_queue &&i_source) noexcept | |
conc_heter_queue & | operator= (conc_heter_queue &&i_source) noexcept |
allocator_type | get_allocator () noexcept(std::is_nothrow_copy_constructible< allocator_type >::value) |
allocator_type & | get_allocator_ref () noexcept |
const allocator_type & | get_allocator_ref () const noexcept |
~conc_heter_queue ()=default | |
bool | empty () const noexcept |
void | clear () noexcept |
template<typename ELEMENT_TYPE > | |
void | push (ELEMENT_TYPE &&i_source) |
template<typename ELEMENT_TYPE , typename... CONSTRUCTION_PARAMS> | |
void | emplace (CONSTRUCTION_PARAMS &&...i_construction_params) |
void | dyn_push (const runtime_type &i_type) |
void | dyn_push_copy (const runtime_type &i_type, const void *i_source) |
void | dyn_push_move (const runtime_type &i_type, void *i_source) |
template<typename ELEMENT_TYPE > | |
put_transaction< typename std::decay< ELEMENT_TYPE >::type > | start_push (ELEMENT_TYPE &&i_source) |
template<typename ELEMENT_TYPE , typename... CONSTRUCTION_PARAMS> | |
put_transaction< ELEMENT_TYPE > | start_emplace (CONSTRUCTION_PARAMS &&...i_construction_params) |
put_transaction | start_dyn_push (const runtime_type &i_type) |
put_transaction | start_dyn_push_copy (const runtime_type &i_type, const void *i_source) |
put_transaction | start_dyn_push_move (const runtime_type &i_type, void *i_source) |
void | pop () noexcept |
bool | try_pop () noexcept |
consume_operation | try_start_consume () noexcept |
bool | try_start_consume (consume_operation &i_consume) noexcept |
template<typename ELEMENT_TYPE > | |
void | reentrant_push (ELEMENT_TYPE &&i_source) |
template<typename ELEMENT_TYPE , typename... CONSTRUCTION_PARAMS> | |
void | reentrant_emplace (CONSTRUCTION_PARAMS &&...i_construction_params) |
void | reentrant_dyn_push (const runtime_type &i_type) |
void | reentrant_dyn_push_copy (const runtime_type &i_type, const void *i_source) |
void | reentrant_dyn_push_move (const runtime_type &i_type, void *i_source) |
template<typename ELEMENT_TYPE > | |
reentrant_put_transaction< typename std::decay< ELEMENT_TYPE >::type > | start_reentrant_push (ELEMENT_TYPE &&i_source) |
template<typename ELEMENT_TYPE , typename... CONSTRUCTION_PARAMS> | |
reentrant_put_transaction< ELEMENT_TYPE > | start_reentrant_emplace (CONSTRUCTION_PARAMS &&...i_construction_params) |
reentrant_put_transaction | start_reentrant_dyn_push (const runtime_type &i_type) |
reentrant_put_transaction | start_reentrant_dyn_push_copy (const runtime_type &i_type, const void *i_source) |
reentrant_put_transaction | start_reentrant_dyn_push_move (const runtime_type &i_type, void *i_source) |
void | reentrant_pop () noexcept |
bool | try_reentrant_pop () noexcept |
reentrant_consume_operation | try_start_reentrant_consume () noexcept |
bool | try_start_reentrant_consume (reentrant_consume_operation &i_consume) noexcept |
Static Public Attributes | |
static constexpr bool | concurrent_puts = true |
static constexpr bool | concurrent_consumes = true |
static constexpr bool | concurrent_put_consumes = true |
static constexpr bool | is_seq_cst = true |
static constexpr size_t | min_alignment = InnerQueue::min_alignment |
Friends | |
void | swap (conc_heter_queue< RUNTIME_TYPE, ALLOCATOR_TYPE > &i_first, conc_heter_queue< RUNTIME_TYPE, ALLOCATOR_TYPE > &i_second) noexcept |
Class template implementing a concurrent heterogeneous FIFO pseudo-container.
conc_heter_queue is a concurrent version of heter_queue, with a mutex embedded within. It allows different threads to put and consume elements concurrently without any external synchronization.
RUNTIME_TYPE | Runtime-type object used to store the actual complete type of each element. This type must satisfy the requirements of RuntimeType. The default is runtime_type. |
ALLOCATOR_TYPE | Allocator type to be used. This type must satisfy the requirements of both UntypedAllocator and PagedAllocator. The default is density::default_allocator. |
Thread safeness: Put and consumes can be executed concurrently. Lifetime function can't.
Exception safeness: Any function of conc_heter_queue is noexcept or provides the strong exception guarantee.
conc_heter_queue is basically an heter_queue protected by an std::mutex to avoid data races.
Non-reentrant operations keep the mutex locked during the whole operation (until the operation is canceled or committed). Reentrant operations minimize the durations of the locks: the mutex is locked once when the operation starts, and another time to commit or cancel the operation.
|
defaultnoexcept |
Default constructor. The allocator is default-constructed.
Complexity: constant.
Throws: nothing.
Exception guarantee: strong (in case of exception the function has no observable effects).
Implementation notes: This constructor does not allocate memory and never throws.
|
inlineexplicitnoexcept |
Constructor with allocator parameter. The allocator is copy-constructed.
i_source_allocator | source used to copy-construct the allocator. |
Complexity: constant.
Throws: whatever the copy constructor of the allocator throws.
Exception guarantee: strong (in case of exception the function has no observable effects).
Implementation notes: This constructor does not allocate memory. It throws anything the copy constructor of the allocator throws.
|
inlineexplicitnoexcept |
Constructor with allocator parameter. The allocator is move-constructed.
i_source_allocator | source used to move-construct the allocator. |
Complexity: constant.
Throws: whatever the move constructor of the allocator throws.
Exception guarantee: strong (in case of exception the function has no observable effects).
Implementation notes: This constructor does not allocate memory. It throws anything the move constructor of the allocator throws.
|
inlinenoexcept |
Move constructor. The allocator is move-constructed from the one of the source.
i_source | source to move the elements from. After the call the source is left in some valid but indeterminate state. |
Complexity: constant.
Throws: nothing.
Implementation notes:
|
default |
Destructor.
Complexity: linear.
Effects on iterators: any iterator pointing to this queue is invalidated.
Throws: Nothing.
|
inlinenoexcept |
Move assignment. The allocator is move-assigned from the one of the source.
i_source | source to move the elements from. After the call the source is left in some valid but indeterminate state. |
Complexity: Unspecified.
Effects on iterators: Any iterator pointing to this queue or to the source queue is invalidated.
Throws: Nothing.
Implementation notes:
|
inlinenoexcept |
Returns a copy of the allocator
|
inlinenoexcept |
Returns a reference to the allocator
|
inlinenoexcept |
Returns a const reference to the allocator
|
inlinenoexcept |
Returns whether the queue contains no elements.
Complexity: Unspecified.
Throws: Nothing.
|
inlinenoexcept |
Deletes all the elements in the queue.
Complexity: linear.
Effects on iterators: any iterator is invalidated
Throws: Nothing.
|
inline |
Appends at the end of the queue an element of type ELEMENT_TYPE
, copy-constructing or move-constructing it from the source.
i_source | object to be used as source to construct of new element.
|
Requires:
ELEMENT_TYPE
must be copy constructible (in case of l-value) or move constructible (in case of r-value)Complexity: constant.
Effects on iterators: no iterator is invalidated
Throws: unspecified.
Exception guarantee: strong (in case of exception the function has no observable effects).
Examples
|
inline |
Appends at the end of the queue an element of type ELEMENT_TYPE
, in-place-constructing it from a perfect forwarded parameter pack.
Note: the template argument ELEMENT_TYPE can't be deduced from the parameters so it must explicitly specified.
i_construction_params | construction parameters for the new element. |
Requires:
ELEMENT_TYPE
must be constructible with std::forward<CONSTRUCTION_PARAMS>(i_construction_params)...
Complexity: constant.
Effects on iterators: no iterator is invalidated
Throws: unspecified.
Exception guarantee: strong (in case of exception the function has no observable effects).
Examples
|
inline |
Adds at the end of the queue an element of a type known at runtime, default-constructing it.
i_type | type of the new element. |
Requires:
RUNTIME_TYPE::default_construct
must be invokable. If RUNTIMETYPE
is runtime_type this means that default_construct
must be included in the feature list.Complexity: constant.
Effects on iterators: no iterator is invalidated
Throws: unspecified.
Exception guarantee: strong (in case of exception the function has no observable effects).
Examples
|
inline |
Appends at the end of the queue an element of a type known at runtime, copy-constructing it from the source.
i_type | type of the new element. |
i_source | pointer to the object to use as source. If this pointer does dot point to an object whose dynamic type is the target type i_type was bound to, the behavior is undefined. |
Requires:
RUNTIME_TYPE::copy_construct
must be invokable. If RUNTIMETYPE
is runtime_type this means that copy_construct
must be included in the feature list.Complexity: constant.
Effects on iterators: no iterator is invalidated
Throws: unspecified.
Exception guarantee: strong (in case of exception the function has no observable effects).
Examples
|
inline |
Adds at the end of the queue an element of a type known at runtime, move-constructing it from the source.
i_type | type of the new element |
i_source | pointer to the object to use as source. If this pointer does dot point to an object whose dynamic type is the target type i_type was bound to, the behavior is undefined. |
Requires:
RUNTIME_TYPE::move_construct
must be invokable. If RUNTIMETYPE
is runtime_type this means that move_construct
must be included in the feature list.Complexity: constant.
Effects on iterators: no iterator is invalidated
Throws: unspecified.
Exception guarantee: strong (in case of exception the function has no observable effects).
Examples
|
inline |
Begins a transaction that appends an element of type ELEMENT_TYPE
, copy-constructing or move-constructing it from the source.
This function allocates the required space, constructs the new element, and returns a transaction object that may be used to allocate raw space associated to the element being inserted, or to alter the element in some way.
Call the member function commit on the returned transaction in order to make the effects observable. If the transaction is destroyed before commit has been called, the transaction is canceled and it has no observable effects. Until the returned transaction is committed or canceled, the queue is not in a consistent state. If any function is called in this timespan by the same thread, the behavior is undefined.
i_source | object to be used as source to construct of new element.
|
Requires:
ELEMENT_TYPE
must be copy constructible (in case of l-value) or move constructible (in case of r-value) Complexity: constant. Examples
|
inline |
Begins a transaction that appends an element of a type ELEMENT_TYPE
, in-place-constructing it from a perfect forwarded parameter pack.
This function allocates the required space, constructs the new element, and returns a transaction object that may be used to allocate raw space associated to the element being inserted, or to alter the element in some way.
Call the member function commit on the returned transaction in order to make the effects observable. If the transaction is destroyed before commit has been called, the transaction is canceled and it has no observable effects. Until the returned transaction is committed or canceled, the queue is not in a consistent state. If any function is called in this timespan by the same thread, the behavior is undefined.
i_construction_params | construction parameters for the new element. |
Requires:
ELEMENT_TYPE
must be constructible with std::forward<CONSTRUCTION_PARAMS>(i_construction_params)...
Complexity: constant.
Effects on iterators: no iterator is invalidated
Throws: unspecified.
Exception guarantee: strong (in case of exception the function has no observable effects).
Examples
|
inline |
Begins a transaction that appends an element of a type known at runtime, default-constructing it.
This function allocates space for and constructs the new element, and returns a transaction object that may be used to allocate raw space associated to the element being inserted, or to alter the element in some way.
Call the member function commit on the returned transaction in order to make the effects observable. If the transaction is destroyed before commit has been called, the transaction is canceled and it has no observable effects. Until the returned transaction is committed or canceled, the queue is not in a consistent state. If any function is called in this timespan by the same thread, the behavior is undefined.
i_type | type of the new element. |
Complexity: constant.
Effects on iterators: no iterator is invalidated
Throws: unspecified.
Exception guarantee: strong (in case of exception the function has no observable effects).
Examples
|
inline |
Begins a transaction that appends an element of a type known at runtime, copy-constructing it from the source..
This function allocates space for and constructs the new element, and returns a transaction object that may be used to allocate raw space associated to the element being inserted, or to alter the element in some way.
Call the member function commit on the returned transaction in order to make the effects observable. If the transaction is destroyed before commit has been called, the transaction is canceled and it has no observable effects. Until the returned transaction is committed or canceled, the queue is not in a consistent state. If any function is called in this timespan by the same thread, the behavior is undefined.
i_type | type of the new element. |
i_source | pointer to the object to use as source. If this pointer does dot point to an object whose dynamic type is the target type i_type was bound to, the behavior is undefined. |
Complexity: constant.
Effects on iterators: no iterator is invalidated
Throws: unspecified.
Exception guarantee: strong (in case of exception the function has no observable effects).
Examples
|
inline |
Begins a transaction that appends an element of a type known at runtime, move-constructing it from the source..
This function allocates space for and constructs the new element, and returns a transaction object that may be used to allocate raw space associated to the element being inserted, or to alter the element in some way.
Call the member function commit on the returned transaction in order to make the effects observable. If the transaction is destroyed before commit has been called, the transaction is canceled and it has no observable effects. Until the returned transaction is committed or canceled, the queue is not in a consistent state. If any function is called in this timespan by the same thread, the behavior is undefined.
i_type | type of the new element. |
i_source | pointer to the object to use as source. If this pointer does dot point to an object whose dynamic type is the target type i_type was bound to, the behavior is undefined. |
Complexity: constant.
Effects on iterators: no iterator is invalidated
Throws: unspecified.
Exception guarantee: strong (in case of exception the function has no observable effects).
Examples
|
inlinenoexcept |
Removes and destroy the first element of the queue. This function discards the element. Use a consume function if you want to access the element before it gets destroyed.
This function is equivalent to:
try_start_consume().commit();
Complexity: constant
Effects on iterators: any iterator pointing to the first element is invalidated
Throws: nothing
|
inlinenoexcept |
Removes and destroy the first element of the queue, if the queue is not empty. Otherwise it has no effect. This function discards the element. Use a consume function if you want to access the element before it gets destroyed.
Complexity: constant.
Effects on iterators: any iterator pointing to the first element is invalidated
Throws: nothing
|
inlinenoexcept |
Tries to start a consume operation.
A non-empty consume must be committed for the consume to have effect.
|
inlinenoexcept |
Tries to start a consume operation using an existing consume_operation object.
i_consume | reference to a consume_operation to be used. If it is non-empty it gets canceled before trying to start the new consume. |
A non-empty consume must be committed for the consume to have effect.
This overload is similar to the one taking no arguments and returning a consume_operation. For an conc_heter_queue there is no performance difference between the two overloads. Anyway for lock-free concurrent queue this overload may be faster.
|
inline |
Same to conc_heter_queue::push, but allows reentrancy: during the construction of the element the queue is in a valid state.
Examples
|
inline |
Same to conc_heter_queue::emplace, but allows reentrancy: during the construction of the element the queue is in a valid state.
Examples
|
inline |
Same to conc_heter_queue::dyn_push, but allows reentrancy: during the construction of the element the queue is in a valid state.
Examples
|
inline |
Same to conc_heter_queue::dyn_push_copy, but allows reentrancy: during the construction of the element the queue is in a valid state.
Examples
|
inline |
Same to conc_heter_queue::dyn_push_move, but allows reentrancy: during the construction of the element the queue is in a valid state.
Examples
|
inline |
Same to conc_heter_queue::start_push, but allows reentrancy: during the construction of the element, and until the state of the transaction gets destroyed, the queue is in a valid state.
Examples
|
inline |
Same to conc_heter_queue::start_emplace, but allows reentrancy: during the construction of the element, and until the state of the transaction gets destroyed, the queue is in a valid state.
Examples
|
inline |
Same to conc_heter_queue::start_dyn_push, but allows reentrancy: during the construction of the element, and until the state of the transaction gets destroyed, the queue is in a valid state.
Examples
|
inline |
Same to conc_heter_queue::start_dyn_push_copy, but allows reentrancy: during the construction of the element, and until the state of the transaction gets destroyed, the queue is in a valid state.
Examples
|
inline |
Same to conc_heter_queue::start_dyn_push_move, but allows reentrancy: during the construction of the element, and until the state of the transaction gets destroyed, the queue is in a valid state.
Examples
|
inlinenoexcept |
Removes and destroy the first element of the queue. This is the reentrant version of pop. This function discards the element. Use a consume function if you want to access the element before it gets destroyed.
This function is equivalent to:
try_start_reentrant_consume().commit();
Complexity: constant
Effects on iterators: any iterator pointing to the first element is invalidated
Throws: nothing
|
inlinenoexcept |
Removes and destroy the first element of the queue, if the queue is not empty. Otherwise it has no effect. This is the reentrant version of try_pop. This function discards the element. Use a consume function if you want to access the element before it gets destroyed.
Complexity: constant.
Effects on iterators: any iterator pointing to the first element is invalidated
Throws: nothing
|
inlinenoexcept |
Tries to start a reentrant consume operation. This is the reentrant version of try_start_consume.
A non-empty consume must be committed for the consume to have effect.
|
inlinenoexcept |
Tries to start a consume operation using an existing consume_operation object. This is the reentrant version of try_start_consume.
i_consume | reference to a consume_operation to be used. If it is non-empty it gets canceled before trying to start the new consume. |
A non-empty consume must be committed for the consume to have effect.
This overload is similar to the one taking no arguments and returning a consume_operation. For an conc_heter_queue there is no performance difference between the two overloads. Anyway for lock-free concurrent queue this overload may be faster.
|
friend |
Swaps two queues.
|
static |
Whether multiple threads can do put operations on the same queue without any further synchronization.
|
static |
Whether multiple threads can do consume operations on the same queue without any further synchronization.
|
static |
Whether puts and consumes can be done concurrently without any further synchronization. In any case unsynchronized concurrency is constrained by concurrent_puts and concurrent_consumes.
|
static |
Whether this queue is sequential consistent.
|
static |
Minimum guaranteed alignment for every element. The actual alignment of an element may be stricter if the type requires it.