cds  2.3.1
cds::container::RWQueue< T, Traits > Class Template Reference

Michael & Scott blocking queue with fine-grained synchronization schema. More...

#include <cds/container/rwqueue.h>

Data Structures

struct  rebind
 Rebind template arguments. More...
 

Public Types

typedef T value_type
 Type of value to be stored in the queue.
 
typedef Traits traits
 Queue traits.
 
typedef traits::lock_type lock_type
 Locking primitive.
 
typedef traits::item_counter item_counter
 Item counting policy used.
 
typedef traits::allocator::template rebind< node_type >::other allocator_type
 Allocator type used for allocate/deallocate the queue nodes.
 

Public Member Functions

 RWQueue ()
 Makes empty queue.
 
 ~RWQueue ()
 Destructor clears queue.
 
bool enqueue (value_type const &data)
 Enqueues data. Always return true.
 
bool enqueue (value_type &&data)
 Enqueues data, move semantics.
 
template<typename Func >
bool enqueue_with (Func f)
 Enqueues data to the queue using a functor. More...
 
template<typename... Args>
bool emplace (Args &&... args)
 Enqueues data of type value_type constructed with std::forward<Args>(args)...
 
bool push (value_type const &val)
 Synonym for enqueue( value_type const& ) function.
 
bool push (value_type &&val)
 Synonym for enqueue( value_type&& ) function.
 
template<typename Func >
bool push_with (Func f)
 Synonym for enqueue_with() function.
 
bool dequeue (value_type &dest)
 Dequeues a value to dest. More...
 
template<typename Func >
bool dequeue_with (Func f)
 Dequeues a value using a functor. More...
 
bool pop (value_type &dest)
 Synonym for dequeue() function.
 
template<typename Func >
bool pop_with (Func f)
 Synonym for dequeue_with() function.
 
bool empty () const
 Checks if queue is empty.
 
void clear ()
 Clears queue.
 
size_t size () const
 Returns queue's item count. More...
 

Detailed Description

template<typename T, typename Traits = rwqueue::traits>
class cds::container::RWQueue< T, Traits >

Michael & Scott blocking queue with fine-grained synchronization schema.

The queue has two different locks: one for reading and one for writing. Therefore, one writer and one reader can simultaneously access to the queue. The queue does not require any garbage collector.

Source

  • [1998] Maged Michael, Michael Scott "Simple, fast, and practical non-blocking and blocking concurrent queue algorithms"

Template arguments

Member Function Documentation

◆ dequeue()

template<typename T , typename Traits = rwqueue::traits>
bool cds::container::RWQueue< T, Traits >::dequeue ( value_type dest)
inline

Dequeues a value to dest.

If queue is empty returns false, dest can be corrupted. If queue is not empty returns true, dest contains the value dequeued

◆ dequeue_with()

template<typename T , typename Traits = rwqueue::traits>
template<typename Func >
bool cds::container::RWQueue< 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::RWQueue< cds::gc::HP, 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_with()

template<typename T , typename Traits = rwqueue::traits>
template<typename Func >
bool cds::container::RWQueue< T, Traits >::enqueue_with ( Func  f)
inline

Enqueues data to the queue using a functor.

Func is a functor called to create node. The functor f takes one argument - a reference to a new node of type value_type :

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

◆ size()

template<typename T, typename Traits = rwqueue::traits>
size_t cds::container::RWQueue< T, Traits >::size ( ) const
inline

Returns queue's item count.

The value returned depends on rwqueue::traits::item_counter. For atomicity::empty_item_counter, this function always returns 0.

Note
Even if you use real item counter and it returns 0, this fact is not mean that the queue is empty. To check queue emptyness use empty() method.

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

cds 2.3.1 Developed by Maxim Khizhinsky aka khizmax 2007 - 2017
Autogenerated Fri Sep 1 2017 08:47:07 by Doxygen 1.8.13