cds  2.3.2
cds::container::VyukovMPMCCycleQueue< T, Traits > Class Template Reference

Vyukov's MPMC bounded queue. More...

#include <cds/container/vyukov_mpmc_cycle_queue.h>

Inheritance diagram for cds::container::VyukovMPMCCycleQueue< T, Traits >:
cds::bounded_container

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
 

Detailed Description

template<typename T, typename Traits = vyukov_queue::traits>
class cds::container::VyukovMPMCCycleQueue< T, Traits >

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

License
Simplified BSD license by Dmitry Vyukov (http://www.1024cores.net/site/1024cores/home/code-license)

Constructor & Destructor Documentation

◆ VyukovMPMCCycleQueue()

template<typename T, typename Traits = vyukov_queue::traits>
cds::container::VyukovMPMCCycleQueue< T, Traits >::VyukovMPMCCycleQueue ( size_t  nCapacity = 0)
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.

Member Function Documentation

◆ dequeue()

template<typename T, typename Traits = vyukov_queue::traits>
bool cds::container::VyukovMPMCCycleQueue< T, Traits >::dequeue ( value_type dest)
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.

◆ dequeue_with()

template<typename T, typename Traits = vyukov_queue::traits>
template<typename Func >
bool cds::container::VyukovMPMCCycleQueue< T, Traits >::dequeue_with ( Func  f)
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:

cds:container::VyukovMPMCCycleQueue< Foo > myQueue;
Bar bar;
myQueue.dequeue_with( [&bar]( Foo& src ) { bar = std::move( src );});

The functor is called only if the queue is not empty.

◆ enqueue()

template<typename T, typename Traits = vyukov_queue::traits>
bool cds::container::VyukovMPMCCycleQueue< T, Traits >::enqueue ( value_type const &  val)
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.

◆ enqueue_with()

template<typename T, typename Traits = vyukov_queue::traits>
template<typename Func >
bool cds::container::VyukovMPMCCycleQueue< T, Traits >::enqueue_with ( Func  f)
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 :

Bar bar;
myQueue.enqueue_with( [&bar]( Foo& dest ) { dest = std::move(bar); } );

◆ size()

template<typename T, typename Traits = vyukov_queue::traits>
size_t cds::container::VyukovMPMCCycleQueue< T, Traits >::size ( ) const
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.


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

cds 2.3.2 Developed by Maxim Khizhinsky aka khizmax and other contributors 2007 - 2017
Autogenerated Sun Dec 31 2017 12:10:29 by Doxygen 1.8.13