cds
2.3.2
|
Vyukov's MPMC bounded queue. More...
#include <cds/container/vyukov_mpmc_cycle_queue.h>
Data Structures | |
struct | rebind |
Rebind template arguments. More... | |
Public Types | |
typedef T | value_type |
Value type to be stored in the queue. | |
typedef Traits | traits |
Queue traits. | |
typedef traits::item_counter | item_counter |
Item counter type. | |
typedef traits::memory_model | memory_model |
Memory ordering. See cds::opt::memory_model option. | |
typedef traits::value_cleaner | value_cleaner |
Value cleaner, see vyukov_queue::traits::value_cleaner . | |
typedef traits::back_off | back_off |
back-off strategy | |
Public Member Functions | |
VyukovMPMCCycleQueue (size_t nCapacity=0) | |
Constructs the queue of capacity nCapacity . More... | |
template<typename Func > | |
bool | enqueue_with (Func f) |
Enqueues data to the queue using a functor. More... | |
bool | enqueue (value_type const &val) |
Enqueues val value into the queue. More... | |
bool | enqueue (value_type &&val) |
Enqueues val value into the queue, move semantics. | |
bool | push (value_type const &data) |
Synonym for enqueue( value_type const& ) | |
bool | push (value_type &&data) |
Synonym for enqueue( value_type&& ) | |
template<typename Func > | |
bool | push_with (Func f) |
Synonym for enqueue_with() | |
template<typename... Args> | |
bool | emplace (Args &&... args) |
Enqueues data of type value_type constructed with std::forward<Args>(args)... | |
template<typename Func > | |
bool | dequeue_with (Func f) |
Dequeues a value using a functor. More... | |
bool | dequeue (value_type &dest) |
Dequeues a value from the queue. More... | |
bool | pop (value_type &data) |
Synonym for dequeue() | |
template<typename Func > | |
bool | pop_with (Func f) |
Synonym for dequeue_with() | |
template<bool SC = c_single_consumer> | |
std::enable_if< SC, value_type * >::type | front () |
Returns a pointer to top element of the queue or nullptr if queue is empty (only for single-consumer version) | |
template<bool SC = c_single_consumer> | |
std::enable_if< SC, bool >::type | pop_front () |
Pops top element; returns true if queue is not empty, false otherwise (only for single-consumer version) | |
bool | empty () const |
Checks if the queue is empty. | |
void | clear () |
Clears the queue. | |
size_t | size () const |
Returns queue's item count. More... | |
size_t | capacity () const |
Returns capacity of the queue. | |
Static Public Attributes | |
static constexpr bool const | c_single_consumer = traits::single_consumer |
true for single-consumer version, false otherwise | |
Vyukov's MPMC bounded queue.
This algorithm is developed by Dmitry Vyukov (see http://www.1024cores.net) It's multi-producer multi-consumer (MPMC), array-based, fails on overflow, does not require GC, w/o priorities, causal FIFO, blocking producers and consumers queue. The algorithm is pretty simple and fast. It's not lock-free in the official meaning, just implemented by means of atomic RMW operations w/o mutexes.
The cost of enqueue/dequeue is 1 CAS per operation. No dynamic memory allocation/management during operation. Producers and consumers are separated from each other (as in the two-lock queue), i.e. do not touch the same data while queue is not empty.
There is multiple producer/single consumer version cds::container::VyukovMPSCCycleQueue
that supports front()
and pop_front()
functions.
Source:
Template parameters
T
- type stored in queue.Traits
- queue traits, default is vyukov_queue::traits
. You can use vyukov_queue::make_traits
metafunction to make your traits or just derive your traits from vyukov_queue::traits
:
|
inline |
Constructs the queue of capacity nCapacity
.
For cds::opt::v::uninitialized_static_buffer
the nCapacity
parameter is ignored.
The buffer capacity must be the power of two.
|
inline |
Dequeues a value from the queue.
If queue is not empty, the function returns true
, dest
contains a copy of dequeued value. The assignment operator for type value_type is invoked. If queue is empty, the function returns false
, dest
is unchanged.
|
inline |
Dequeues a value using a functor.
Func
is a functor called to copy dequeued value. The functor takes one argument - a reference to removed node:
The functor is called only if the queue is not empty.
|
inline |
Enqueues val
value into the queue.
The new queue item is created by calling placement new in free cell. Returns true
if success, false
if the queue is full.
|
inline |
Enqueues data to the queue using a functor.
Func
is a functor called to copy a value to the queue cell. The functor f
takes one argument - a reference to a empty cell of type value_type :
|
inline |
Returns queue's item count.
The value returned depends on vyukov_queue::traits::item_counter
option. For atomicity::empty_item_counter
, the function always returns 0.