cds
2.3.2
|
Optimistic intruive lock-free queue. More...
#include <cds/intrusive/optimistic_queue.h>
Data Structures | |
struct | rebind |
Rebind template arguments. More... | |
Public Types | |
typedef GC | gc |
Garbage collector. | |
typedef T | value_type |
type of value to be stored in the queue | |
typedef Traits | traits |
Queue traits. | |
typedef traits::hook | hook |
hook type | |
typedef hook::node_type | node_type |
node type | |
typedef traits::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, traits::link_checker >::type | link_checker |
link checker | |
typedef traits::back_off | back_off |
back-off strategy | |
typedef traits::item_counter | item_counter |
Item counting policy used. | |
typedef traits::memory_model | memory_model |
Memory ordering. See cds::opt::memory_model option. | |
typedef traits::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 the 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. | |
Static Public Attributes | |
static constexpr const size_t | c_nHazardPtrCount = 5 |
Count of hazard pointer required for the algorithm. | |
Protected Attributes | |
atomic_node_ptr | m_pTail |
Pointer to tail node. | |
atomic_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. | |
Optimistic intruive lock-free queue.
Implementation of Ladan-Mozes & Shavit optimistic queue algorithm. [2008] Edya Ladan-Mozes, Nir Shavit "An Optimistic Approach to Lock-Free FIFO Queues"
Template arguments:
GC
- garbage collector type: gc::HP
, gc::DHP
T
- type of value to be stored in the queue. A value of type T
must be derived from optimistic_queue::node
for optimistic_queue::base_hook
, or it should have a member of type optimistic_queue::node
for optimistic_queue::member_hook
, or it should be convertible to optimistic_queue::node
for optimistic_queue::traits_hook
.Traits
- queue traits, default is optimistic_queue::traits
. You can use optimistic_queue::make_traits
metafunction to make your traits or just derive your traits from optimistic_queue::traits
: Garbage collecting schema GC
must be consistent with the optimistic_queue::node GC.
dequeue()
function for explanation.
|
inline |
Clear the stack.
The function repeatedly calls dequeue until it returns nullptr
. The disposer defined in template Traits
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 nullptr
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 the queue 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 optimistic_queue::traits::item_counter
. For atomicity::empty_item_counter
, this function always returns 0.
empty()
method.