density
C++11 library for paged memory management, function queues, heterogeneous queues and lifo memory management
Classes | Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
conc_heter_queue< RUNTIME_TYPE, ALLOCATOR_TYPE > Class Template Reference

#include <conc_heter_queue.h>

Classes

class  consume_operation
 
class  put_transaction
 
class  reentrant_consume_operation
 
class  reentrant_put_transaction
 

Public Types

using runtime_type = RUNTIME_TYPE
 
using value_type = std::pair< const runtime_type &, void *const >
 
using allocator_type = ALLOCATOR_TYPE
 
using pointer = value_type *
 
using const_pointer = const value_type *
 
using reference = value_type
 
using const_reference = const value_type &
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 

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_queueoperator= (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
 

Detailed Description

template<typename RUNTIME_TYPE = runtime_type<>, typename ALLOCATOR_TYPE = default_allocator>
class density::conc_heter_queue< RUNTIME_TYPE, ALLOCATOR_TYPE >

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.

Template Parameters
RUNTIME_TYPERuntime-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_TYPEAllocator 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.

Implementation and performance notes

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.

Constructor & Destructor Documentation

constexpr conc_heter_queue ( )
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.

conc_heter_queue<> queue;
assert(queue.empty());
constexpr conc_heter_queue ( const ALLOCATOR_TYPE &  i_source_allocator)
inlineexplicitnoexcept

Constructor with allocator parameter. The allocator is copy-constructed.

Parameters
i_source_allocatorsource 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.

default_allocator allocator;
conc_heter_queue<> queue(allocator);
assert(queue.empty());
constexpr conc_heter_queue ( ALLOCATOR_TYPE &&  i_source_allocator)
inlineexplicitnoexcept

Constructor with allocator parameter. The allocator is move-constructed.

Parameters
i_source_allocatorsource 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.

default_allocator allocator;
conc_heter_queue<> queue(std::move(allocator));
assert(queue.empty());
conc_heter_queue ( conc_heter_queue< RUNTIME_TYPE, ALLOCATOR_TYPE > &&  i_source)
inlinenoexcept

Move constructor. The allocator is move-constructed from the one of the source.

Parameters
i_sourcesource to move the elements from. After the call the source is left in some valid but indeterminate state.

Complexity: constant.
Throws: nothing.
Implementation notes:

  • After the call the source is left empty.
using MyRunTimeType = runtime_type<
f_default_construct,
f_copy_construct,
f_destroy,
f_size,
f_alignment,
f_equal>;
conc_heter_queue<MyRunTimeType> queue;
queue.push(std::string());
queue.push(std::make_pair(4., 1));
conc_heter_queue<MyRunTimeType> queue_1(std::move(queue));
assert(queue.empty());
assert(!queue_1.empty());
~conc_heter_queue ( )
default

Destructor.

Complexity: linear.
Effects on iterators: any iterator pointing to this queue is invalidated.
Throws: Nothing.

Member Function Documentation

conc_heter_queue& operator= ( conc_heter_queue< RUNTIME_TYPE, ALLOCATOR_TYPE > &&  i_source)
inlinenoexcept

Move assignment. The allocator is move-assigned from the one of the source.

Parameters
i_sourcesource 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:

  • After the call the source is left empty.
  • The complexity is linear in the number of elements in this queue.
using MyRunTimeType = runtime_type<
f_default_construct,
f_copy_construct,
f_destroy,
f_size,
f_alignment,
f_equal>;
conc_heter_queue<MyRunTimeType> queue;
queue.push(std::string());
queue.push(std::make_pair(4., 1));
conc_heter_queue<MyRunTimeType> queue_1;
queue_1 = std::move(queue);
assert(queue.empty());
assert(!queue_1.empty());
allocator_type get_allocator ( )
inlinenoexcept

Returns a copy of the allocator

conc_heter_queue<> queue;
assert(queue.get_allocator() == default_allocator());
allocator_type& get_allocator_ref ( )
inlinenoexcept

Returns a reference to the allocator

conc_heter_queue<> queue;
assert(queue.get_allocator_ref() == default_allocator());
const allocator_type& get_allocator_ref ( ) const
inlinenoexcept

Returns a const reference to the allocator

conc_heter_queue<> queue;
auto const & queue_ref = queue;
assert(queue_ref.get_allocator_ref() == default_allocator());
bool empty ( ) const
inlinenoexcept

Returns whether the queue contains no elements.

Complexity: Unspecified.
Throws: Nothing.

conc_heter_queue<> queue;
assert(queue.empty());
queue.push(1);
assert(!queue.empty());
void clear ( )
inlinenoexcept

Deletes all the elements in the queue.

Complexity: linear.
Effects on iterators: any iterator is invalidated
Throws: Nothing.

conc_heter_queue<> queue;
queue.push(1);
queue.clear();
assert(queue.empty());
void push ( ELEMENT_TYPE &&  i_source)
inline

Appends at the end of the queue an element of type ELEMENT_TYPE, copy-constructing or move-constructing it from the source.

Parameters
i_sourceobject to be used as source to construct of new element.
  • If this argument is an l-value, the new element copy-constructed
  • If this argument is an r-value, the new element move-constructed


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

queue.push(12);
queue.push(std::string("Hello world!!"));
void emplace ( CONSTRUCTION_PARAMS &&...  i_construction_params)
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.

Parameters
i_construction_paramsconstruction 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

queue.emplace<int>();
queue.emplace<std::string>(12, '-');
void dyn_push ( const runtime_type &  i_type)
inline

Adds at the end of the queue an element of a type known at runtime, default-constructing it.

Parameters
i_typetype of the new element.


Requires:

  • The function 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

using MyRunTimeType = runtime_type<f_default_construct, f_destroy, f_size, f_alignment>;
conc_heter_queue<MyRunTimeType> queue;
auto const type = MyRunTimeType::make<int>();
queue.dyn_push(type); // appends 0
void dyn_push_copy ( const runtime_type &  i_type,
const void *  i_source 
)
inline

Appends at the end of the queue an element of a type known at runtime, copy-constructing it from the source.

Parameters
i_typetype of the new element.
i_sourcepointer 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:

  • The function 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

using MyRunTimeType = runtime_type<f_copy_construct, f_destroy, f_size, f_alignment>;
conc_heter_queue<MyRunTimeType> queue;
std::string const source("Hello world!!");
auto const type = MyRunTimeType::make<decltype(source)>();
queue.dyn_push_copy(type, &source);
void dyn_push_move ( const runtime_type &  i_type,
void *  i_source 
)
inline

Adds at the end of the queue an element of a type known at runtime, move-constructing it from the source.

Parameters
i_typetype of the new element
i_sourcepointer 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:

  • The function 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

using MyRunTimeType = runtime_type<f_move_construct, f_destroy, f_size, f_alignment>;
conc_heter_queue<MyRunTimeType> queue;
std::string source("Hello world!!");
auto const type = MyRunTimeType::make<decltype(source)>();
queue.dyn_push_move(type, &source);
put_transaction<typename std::decay<ELEMENT_TYPE>::type> start_push ( ELEMENT_TYPE &&  i_source)
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.

Parameters
i_sourceobject to be used as source to construct of new element.
  • If this argument is an l-value, the new element copy-constructed.
  • If this argument is an r-value, the new element move-constructed.
Returns
The associated transaction object.


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

auto put = queue.start_push(12);
put.element() += 2;
put.commit(); // commits a 14
put_transaction<ELEMENT_TYPE> start_emplace ( CONSTRUCTION_PARAMS &&...  i_construction_params)
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.

Parameters
i_construction_paramsconstruction parameters for the new element.
Returns
The associated transaction object.


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

auto put = queue.start_emplace<std::string>(4, '*');
put.element() += "****";
put.commit(); // commits a "********"
put_transaction start_dyn_push ( const runtime_type &  i_type)
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.

Parameters
i_typetype of the new element.
Returns
The associated transaction object.

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

using MyRunTimeType = runtime_type<f_default_construct, f_destroy, f_size, f_alignment>;
conc_heter_queue<MyRunTimeType> queue;
auto const type = MyRunTimeType::make<int>();
auto put = queue.start_dyn_push(type);
put.commit();
put_transaction start_dyn_push_copy ( const runtime_type &  i_type,
const void *  i_source 
)
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.

Parameters
i_typetype of the new element.
i_sourcepointer 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.
Returns
The associated transaction object.

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

using MyRunTimeType = runtime_type<f_copy_construct, f_destroy, f_size, f_alignment>;
conc_heter_queue<MyRunTimeType> queue;
std::string const source("Hello world!!");
auto const type = MyRunTimeType::make<decltype(source)>();
auto put = queue.start_dyn_push_copy(type, &source);
put.commit();
put_transaction start_dyn_push_move ( const runtime_type &  i_type,
void *  i_source 
)
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.

Parameters
i_typetype of the new element.
i_sourcepointer 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.
Returns
The associated transaction object.

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

using MyRunTimeType = runtime_type<f_move_construct, f_destroy, f_size, f_alignment>;
conc_heter_queue<MyRunTimeType> queue;
std::string source("Hello world!!");
auto const type = MyRunTimeType::make<decltype(source)>();
auto put = queue.start_dyn_push_move(type, &source);
put.commit();
void pop ( )
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();

Precondition
The behavior is undefined if the queue is empty.

Complexity: constant
Effects on iterators: any iterator pointing to the first element is invalidated
Throws: nothing

conc_heter_queue<> queue;
queue.push(1);
queue.push(2);
queue.pop();
auto consume = queue.try_start_consume();
assert(consume.element<int>() == 2);
consume.commit();
bool try_pop ( )
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.

Returns
whether an element was actually removed.

Complexity: constant.
Effects on iterators: any iterator pointing to the first element is invalidated
Throws: nothing

conc_heter_queue<> queue;
bool pop_result = queue.try_pop();
assert(pop_result == false);
queue.push(1);
queue.push(2);
pop_result = queue.try_pop();
assert(pop_result == true);
auto consume = queue.try_start_consume();
assert(consume.element<int>() == 2);
consume.commit();
consume_operation try_start_consume ( )
inlinenoexcept

Tries to start a consume operation.

Returns
a consume_operation which is empty if there are no elements to consume

A non-empty consume must be committed for the consume to have effect.

conc_heter_queue<> queue;
auto consume_1 = queue.try_start_consume();
assert(!consume_1);
queue.push(42);
auto consume_2 = queue.try_start_consume();
assert(consume_2);
assert(consume_2.element<int>() == 42);
consume_2.commit();
bool try_start_consume ( consume_operation i_consume)
inlinenoexcept

Tries to start a consume operation using an existing consume_operation object.

Parameters
i_consumereference to a consume_operation to be used. If it is non-empty it gets canceled before trying to start the new consume.
Returns
whether i_consume is non-empty after the call, that is whether the queue was not empty.

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.

conc_heter_queue<> queue;
conc_heter_queue<>::consume_operation consume_1;
bool const bool_1 = queue.try_start_consume(consume_1);
assert(!bool_1 && !consume_1);
queue.push(42);
conc_heter_queue<>::consume_operation consume_2;
auto bool_2 = queue.try_start_consume(consume_2);
assert(consume_2 && bool_2);
assert(consume_2.element<int>() == 42);
consume_2.commit();
void reentrant_push ( ELEMENT_TYPE &&  i_source)
inline

Same to conc_heter_queue::push, but allows reentrancy: during the construction of the element the queue is in a valid state.

Examples

queue.reentrant_push(12);
queue.reentrant_push(std::string("Hello world!!"));
void reentrant_emplace ( CONSTRUCTION_PARAMS &&...  i_construction_params)
inline

Same to conc_heter_queue::emplace, but allows reentrancy: during the construction of the element the queue is in a valid state.

Examples

queue.reentrant_emplace<int>();
queue.reentrant_emplace<std::string>(12, '-');
void reentrant_dyn_push ( const runtime_type &  i_type)
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

using MyRunTimeType = runtime_type<f_default_construct, f_destroy, f_size, f_alignment>;
conc_heter_queue<MyRunTimeType> queue;
auto const type = MyRunTimeType::make<int>();
queue.reentrant_dyn_push(type); // appends 0
void reentrant_dyn_push_copy ( const runtime_type &  i_type,
const void *  i_source 
)
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

using MyRunTimeType = runtime_type<f_copy_construct, f_destroy, f_size, f_alignment>;
conc_heter_queue<MyRunTimeType> queue;
std::string const source("Hello world!!");
auto const type = MyRunTimeType::make<decltype(source)>();
queue.reentrant_dyn_push_copy(type, &source);
void reentrant_dyn_push_move ( const runtime_type &  i_type,
void *  i_source 
)
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

using MyRunTimeType = runtime_type<f_move_construct, f_destroy, f_size, f_alignment>;
conc_heter_queue<MyRunTimeType> queue;
std::string source("Hello world!!");
auto const type = MyRunTimeType::make<decltype(source)>();
queue.reentrant_dyn_push_move(type, &source);
reentrant_put_transaction<typename std::decay<ELEMENT_TYPE>::type> start_reentrant_push ( ELEMENT_TYPE &&  i_source)
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

auto put = queue.start_reentrant_push(12);
put.element() += 2;
put.commit(); // commits a 14
reentrant_put_transaction<ELEMENT_TYPE> start_reentrant_emplace ( CONSTRUCTION_PARAMS &&...  i_construction_params)
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

auto put = queue.start_reentrant_emplace<std::string>(4, '*');
put.element() += "****";
put.commit(); // commits a "********"
reentrant_put_transaction start_reentrant_dyn_push ( const runtime_type &  i_type)
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

using MyRunTimeType = runtime_type<f_default_construct, f_destroy, f_size, f_alignment>;
conc_heter_queue<MyRunTimeType> queue;
auto const type = MyRunTimeType::make<int>();
auto put = queue.start_reentrant_dyn_push(type);
put.commit();
reentrant_put_transaction start_reentrant_dyn_push_copy ( const runtime_type &  i_type,
const void *  i_source 
)
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

using MyRunTimeType = runtime_type<f_copy_construct, f_destroy, f_size, f_alignment>;
conc_heter_queue<MyRunTimeType> queue;
std::string const source("Hello world!!");
auto const type = MyRunTimeType::make<decltype(source)>();
auto put = queue.start_reentrant_dyn_push_copy(type, &source);
put.commit();
reentrant_put_transaction start_reentrant_dyn_push_move ( const runtime_type &  i_type,
void *  i_source 
)
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

using MyRunTimeType = runtime_type<f_move_construct, f_destroy, f_size, f_alignment>;
conc_heter_queue<MyRunTimeType> queue;
std::string source("Hello world!!");
auto const type = MyRunTimeType::make<decltype(source)>();
auto put = queue.start_reentrant_dyn_push_move(type, &source);
put.commit();
void reentrant_pop ( )
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();

Precondition
The behavior is undefined if the queue is empty.

Complexity: constant
Effects on iterators: any iterator pointing to the first element is invalidated
Throws: nothing

conc_heter_queue<> queue;
queue.push(1);
queue.push(2);
queue.reentrant_pop();
auto consume = queue.try_start_consume();
assert(consume.element<int>() == 2);
consume.commit();
bool try_reentrant_pop ( )
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.

Returns
whether an element was actually removed.

Complexity: constant.
Effects on iterators: any iterator pointing to the first element is invalidated
Throws: nothing

conc_heter_queue<> queue;
bool pop_result = queue.try_reentrant_pop();
assert(pop_result == false);
queue.push(1);
queue.push(2);
pop_result = queue.try_reentrant_pop();
assert(pop_result == true);
auto consume = queue.try_start_reentrant_consume();
assert(consume.element<int>() == 2);
consume.commit();
reentrant_consume_operation try_start_reentrant_consume ( )
inlinenoexcept

Tries to start a reentrant consume operation. This is the reentrant version of try_start_consume.

Returns
a consume_operation which is empty if there are no elements to consume

A non-empty consume must be committed for the consume to have effect.

conc_heter_queue<> queue;
auto consume_1 = queue.try_start_reentrant_consume();
assert(!consume_1);
queue.push(42);
auto consume_2 = queue.try_start_reentrant_consume();
assert(consume_2);
assert(consume_2.element<int>() == 42);
consume_2.commit();
bool try_start_reentrant_consume ( reentrant_consume_operation i_consume)
inlinenoexcept

Tries to start a consume operation using an existing consume_operation object. This is the reentrant version of try_start_consume.

Parameters
i_consumereference to a consume_operation to be used. If it is non-empty it gets canceled before trying to start the new consume.
Returns
whether i_consume is non-empty after the call, that is whether the queue was not empty.

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.

conc_heter_queue<> queue;
conc_heter_queue<>::reentrant_consume_operation consume_1;
bool const bool_1 = queue.try_start_reentrant_consume(consume_1);
assert(!bool_1 && !consume_1);
queue.push(42);
conc_heter_queue<>::reentrant_consume_operation consume_2;
auto bool_2 = queue.try_start_reentrant_consume(consume_2);
assert(consume_2 && bool_2);
assert(consume_2.element<int>() == 42);
consume_2.commit();

Friends And Related Function Documentation

void swap ( conc_heter_queue< RUNTIME_TYPE, ALLOCATOR_TYPE > &  i_first,
conc_heter_queue< RUNTIME_TYPE, ALLOCATOR_TYPE > &  i_second 
)
friend

Swaps two queues.

conc_heter_queue<> queue, queue_1;
queue.push(1);
swap(queue, queue_1);
assert(queue.empty());
assert(!queue_1.empty());

Member Data Documentation

constexpr bool concurrent_puts = true
static

Whether multiple threads can do put operations on the same queue without any further synchronization.

constexpr bool concurrent_consumes = true
static

Whether multiple threads can do consume operations on the same queue without any further synchronization.

constexpr bool concurrent_put_consumes = true
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.

constexpr bool is_seq_cst = true
static

Whether this queue is sequential consistent.

constexpr size_t min_alignment = InnerQueue::min_alignment
static

Minimum guaranteed alignment for every element. The actual alignment of an element may be stricter if the type requires it.


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