cds
2.3.2
|
Treiber intrusive stack. More...
#include <cds/intrusive/treiber_stack.h>
Data Structures | |
struct | rebind |
Rebind template arguments. More... | |
Public Types | |
typedef GC | gc |
Garbage collector. | |
typedef T | value_type |
type of value stored in the stack | |
typedef Traits | traits |
Stack 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 single_link::get_link_checker< node_type, traits::link_checker >::type | link_checker |
link checker | |
typedef traits::memory_model | memory_model |
Memory ordering. See cds::opt::memory_model option. | |
typedef traits::item_counter | item_counter |
Item counter class. | |
typedef traits::stat | stat |
Internal statistics. | |
typedef traits::back_off | back_off |
back-off strategy | |
typedef traits::elimination_backoff | elimination_backoff_type |
back-off strategy used to wait for elimination | |
typedef traits::lock_type | elimination_lock_type |
Lock type used in elimination back-off. | |
typedef traits::random_engine | elimination_random_engine |
Random engine used in elimination back-off. | |
Public Member Functions | |
TreiberStack () | |
Constructs empty stack. | |
TreiberStack (size_t nCollisionCapacity) | |
Constructs empty stack and initializes elimination back-off data. More... | |
TreiberStack (TreiberStack const &)=delete | |
TreiberStack is not copy-constructible | |
~TreiberStack () | |
Destructor calls clear member function. | |
bool | push (value_type &val) |
Push the item val on the stack. More... | |
value_type * | pop () |
Pop an item from the stack. More... | |
bool | empty () const |
Check if stack is empty. | |
void | clear () |
Clear the stack. More... | |
size_t | size () const |
Returns stack's item count. More... | |
stat const & | statistics () const |
Returns reference to internal statistics. | |
Static Public Attributes | |
static constexpr size_t const | c_nHazardPtrCount = 1 |
How many Hazard pointers is required for Treiber's stack implementation. | |
static constexpr const bool | enable_elimination = traits::enable_elimination |
Elimination back-off is enabled or not. | |
Protected Attributes | |
node_type::atomic_node_ptr | m_Top |
Top of the stack. | |
item_counter | m_ItemCounter |
Item counter. | |
stat | m_stat |
Internal statistics. | |
Treiber intrusive stack.
Intrusive implementation of well-known Treiber's stack algorithm:
Elimination back-off technique can be used optionally. The idea of elimination algorithm is taken from:
The elimination algorithm uses a single elimination array as a back-off schema on a shared lock-free stack. If the threads fail on the stack, they attempt to eliminate on the array, and if they fail in eliminating, they attempt to access the stack again and so on.
Template arguments:
GC
- garbage collector type: gc::HP
, gc::DHP
. Garbage collecting schema must be the same as treiber_stack::node
GC.T
- a type the stack contains. A value of type T
must be derived from treiber_stack::node
for treiber_stack::base_hook
, or it should have a member of type treiber_stack::node
for treiber_stack::member_hook
, or it should be convertible to treiber_stack::node
for treiber_stack::traits_hook
.Traits
- stack traits, default is treiber_stack::traits
. You can use treiber_stack::make_traits
metafunction to make your traits or just derive your traits from treiber_stack::traits
: Example of how to use treiber_stack::base_hook
. Your class that objects will be pushed on TreiberStack
should be based on treiber_stack::node
class
Example of how to use treiber_stack::base_hook
with different tags.
Example of how to use treiber_stack::member_hook
. Your class should have a member of type treiber_stack::node
|
inline |
Constructs empty stack and initializes elimination back-off data.
This form should be used if you use elimination back-off with dynamically allocated collision array, i.e Traits
contains typedef cds::opt::v::initialized_dynamic_buffer buffer
. nCollisionCapacity
parameter specifies the capacity of collision array.
|
inline |
|
inline |
Pop an item from the stack.
If stack is empty, returns nullptr
. The disposer is not called for popped item. See Destroying items of intrusive containers.
|
inline |
Push the item val
on the stack.
No copying is made since it is intrusive stack.
|
inline |
Returns stack's item count.
The value returned depends on opt::item_counter option. For atomicity::empty_item_counter, this function always returns 0.