|
cds
1.4.0
|
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 |
| typedef options::item_counter | item_counter |
| Item counter type. | |
| typedef options::memory_model | memory_model |
| Memory ordering. See cds::opt::memory_model option. | |
Public Member Functions | |
| VyukovMPMCCycleQueue (size_t nCapacity=0) | |
Constructs the queue of capacity nCapacity. More... | |
| template<typename Source , typename Func > | |
| bool | enqueue (Source const &data, Func func) |
Enqueues data to queue using copy functor. More... | |
| bool | enqueue (value_type const &data) |
| template<typename... Args> | |
| bool | emplace (Args &&...args) |
Enqueues data of type value_type constructed with std::forward<Args>(args)... More... | |
| template<typename Dest , typename Func > | |
| bool | dequeue (Dest &data, Func func) |
| Dequeues an item from queue. More... | |
| bool | dequeue (value_type &data) |
Dequeues an item from queue to data. More... | |
| bool | push (value_type const &data) |
| Synonym of enqueue. | |
| template<typename Source , typename Func > | |
| bool | push (const Source &data, Func f) |
| Synonym for template version of enqueue function. | |
| bool | pop (value_type &data) |
| Synonym of dequeue. | |
| template<typename Type , typename Func > | |
| bool | pop (Type &dest, Func f) |
| Synonym for template version of dequeue function. | |
| 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 cyclic buffer. | |
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.
T - type stored in queue. Options - queue's optionsOptions are:T. After an item is dequeued, value_cleaner cleans the cell that the item has been occupied. If T is a complex type, value_cleaner may be the useful feature.| typedef T cds::container::VyukovMPMCCycleQueue< T, Options >::value_type |
|
inline |
Constructs the queue of capacity nCapacity.
For cds::opt::v::static_buffer the nCapacity parameter is ignored.
|
inline |
Dequeues an item from queue.
Func is a functor called to copy dequeued value of type T to dest of type Dest. The functor's interface is:
You may use boost:ref construction to pass functor func by reference.
Requirements The functor Func should not throw any exception.
|
inline |
|
inline |
Enqueues data of type value_type constructed with std::forward<Args>(args)...
This function is available only for compiler that supports variadic template and move semantics
|
inline |
Enqueues data to queue using copy functor.
Func is a functor called to copy value data of type Source which may be differ from type T stored in the queue. The functor's interface is:
You may use boost:ref construction to pass functor f by reference.
Requirements The functor Func should not throw any exception.
|
inline |
|
inline |
Returns queue's item count.
The value returned depends on opt::item_counter option. For atomicity::empty_item_counter, this function always returns 0.