|
cds
1.4.0
|
Optimistic queue. More...
#include <cds/intrusive/optimistic_queue.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 optimistic_queue::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::memory_model | memory_model |
| Memory ordering. See cds::opt::memory_model option. | |
| typedef options::stat | stat |
| Internal statistics policy used. | |
Public Member Functions | |
| OptimisticQueue () | |
| Constructor creates empty queue. | |
| bool | enqueue (value_type &val) |
| value_type * | dequeue () |
| Dequeues a value from the queue. More... | |
| bool | push (value_type &val) |
| Synonym for enqueue. | |
| value_type * | pop () |
| Synonym for dequeue. | |
| bool | empty () const |
| Checks if queue is empty. | |
| void | clear () |
| Clear the stack. More... | |
| size_t | size () const |
| Returns queue's item count. More... | |
| const stat & | statistics () const |
| Returns refernce to internal statistics. | |
Protected Attributes | |
| aligned_node_ptr | m_pTail |
| Pointer to tail node. | |
| aligned_node_ptr | m_pHead |
| Pointer to head node. | |
| node_type | m_Dummy |
| dummy node | |
| item_counter | m_ItemCounter |
| Item counter. | |
| stat | m_Stat |
| Internal statistics. | |
Static Protected Attributes | |
| static const size_t | m_nHazardPtrCount = 5 |
| Count of hazard pointer required for the algorithm. | |
Optimistic queue.
Implementation of Ladan-Mozes & Shavit optimistic queue algorithm.
Template arguments:
GC - garbage collector type: gc::HP, gc::PTB. Note that gc::HRC is not supportedT - type to be stored in the queueOptions - optionsType of node: optimistic_queue::node.
Options are:
optimistic_queue::base_hook<> is used.Garbage collecting schema GC must be consistent with the optimistic_queue::node GC.
|
inline |
Clear the stack.
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 |
|
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.