|
cds
1.3.0
|
Michael & Scott's lock-free queue (intrusive variant) More...
#include <cds/intrusive/msqueue.h>
Data Structures | |
| struct | rebind |
| Rebind template arguments. More... | |
Public Types | |
| typedef T | value_type |
| type of value stored in the queue | |
| typedef options::hook | hook |
| hook type | |
| typedef hook::node_type | node_type |
| node type | |
| typedef options::disposer | disposer |
| disposer used | |
|
typedef get_node_traits < value_type, node_type, hook > ::type | node_traits |
| node traits | |
|
typedef single_link::get_link_checker < node_type, options::link_checker >::type | link_checker |
| link checker | |
| typedef GC | gc |
| Garbage collector. | |
| typedef options::back_off | back_off |
| back-off strategy | |
| typedef options::item_counter | item_counter |
| Item counting policy used. | |
| typedef options::stat | stat |
| Internal statistics policy used. | |
| typedef options::memory_model | memory_model |
| Memory ordering. See cds::opt::memory_model option. | |
Public Member Functions | |
| MSQueue () | |
| Initializes empty queue. | |
| ~MSQueue () | |
| Destructor clears the queue. | |
| size_t | size () const |
| Returns queue's item count. | |
| const stat & | statistics () const |
| Returns reference to internal statistics. | |
| bool | enqueue (value_type &val) |
Enqueues val value into the queue. | |
| value_type * | dequeue () |
| Dequeues a value from the queue. | |
| bool | push (value_type &val) |
| Synonym for enqueue function. | |
| value_type * | pop () |
| Synonym for dequeue function. | |
| bool | empty () const |
| Checks if the queue is empty. | |
| void | clear () |
| Clear the queue. | |
Michael & Scott's lock-free queue (intrusive variant)
Implementation of well-known Michael & Scott's queue algorithm.
Template arguments:
GC - garbage collector type: gc::HP, gc::HRC, gc::PTBT - type to be stored in the queue, should be convertible to single_link::nodeOptions - optionsType of node: single_link::node
Options are:
single_link::base_hook<> is used. For Gidenstam's gc::HRC, only single_link::base_hook is supported.Garbage collecting schema GC must be consistent with the single_link::node GC.
|
inline |
Destructor clears the queue.
Since the Michael & Scott queue contains at least one item even if the queue is empty, the destructor may call item disposer.
|
inline |
Clear the queue.
The function repeatedly calls dequeue until it returns NULL. The disposer defined in template Options is called for each item that can be safely disposed.
|
inline |
Dequeues a value from the queue.
If the queue is empty the function returns NULL.
dequeue is called, the item returning is still queue's top, and previous top is disposed:dequeue function returns Item 2, that becomes new top of queue, and calls the disposer for Item 1, that was queue's top on function entry. Thus, you cannot manually delete item returned because it is still included in item sequence and it has valuable link field that must not be zeroed. The item may be deleted only in disposer call.
|
inline |
Enqueues val value into the queue.
The function always returns true.
|
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.
Warning: 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.