xrpld
Loading...
Searching...
No Matches
beast::LockFreeStack< Element, Tag > Class Template Reference

Multiple Producer, Multiple Consumer (MPMC) intrusive stack. More...

#include <LockFreeStack.h>

Collaboration diagram for beast::LockFreeStack< Element, Tag >:

Classes

class  Node

Public Types

using value_type = Element
using pointer = Element*
using reference = Element&
using const_pointer = Element const*
using const_reference = Element const&
using size_type = std::size_t
using difference_type = std::ptrdiff_t
using iterator = LockFreeStackIterator<LockFreeStack<Element, Tag>, false>
using const_iterator = LockFreeStackIterator<LockFreeStack<Element, Tag>, true>

Public Member Functions

 LockFreeStack ()
 LockFreeStack (LockFreeStack const &)=delete
LockFreeStackoperator= (LockFreeStack const &)=delete
bool empty () const
 Returns true if the stack is empty.
bool pushFront (Node *node)
 Push a node onto the stack.
Element * popFront ()
 Pop an element off the stack.
iterator begin ()
 Return a forward iterator to the beginning or end of the stack.
iterator end ()
const_iterator begin () const
const_iterator end () const
const_iterator cbegin () const
const_iterator cend () const

Private Attributes

Node end_
std::atomic< Node * > head_

Detailed Description

template<class Element, class Tag = void>
class beast::LockFreeStack< Element, Tag >

Multiple Producer, Multiple Consumer (MPMC) intrusive stack.

This stack is implemented using the same intrusive interface as List. All mutations are lock-free.

The caller is responsible for preventing the "ABA" problem: http://en.wikipedia.org/wiki/ABA_problem

Parameters
TagA type name used to distinguish lists and nodes, for putting objects in multiple lists. If this parameter is omitted, the default tag is used.

Definition at line 118 of file LockFreeStack.h.

Member Typedef Documentation

◆ value_type

template<class Element, class Tag = void>
using beast::LockFreeStack< Element, Tag >::value_type = Element

Definition at line 146 of file LockFreeStack.h.

◆ pointer

template<class Element, class Tag = void>
using beast::LockFreeStack< Element, Tag >::pointer = Element*

Definition at line 147 of file LockFreeStack.h.

◆ reference

template<class Element, class Tag = void>
using beast::LockFreeStack< Element, Tag >::reference = Element&

Definition at line 148 of file LockFreeStack.h.

◆ const_pointer

template<class Element, class Tag = void>
using beast::LockFreeStack< Element, Tag >::const_pointer = Element const*

Definition at line 149 of file LockFreeStack.h.

◆ const_reference

template<class Element, class Tag = void>
using beast::LockFreeStack< Element, Tag >::const_reference = Element const&

Definition at line 150 of file LockFreeStack.h.

◆ size_type

template<class Element, class Tag = void>
using beast::LockFreeStack< Element, Tag >::size_type = std::size_t

Definition at line 151 of file LockFreeStack.h.

◆ difference_type

template<class Element, class Tag = void>
using beast::LockFreeStack< Element, Tag >::difference_type = std::ptrdiff_t

Definition at line 152 of file LockFreeStack.h.

◆ iterator

template<class Element, class Tag = void>
using beast::LockFreeStack< Element, Tag >::iterator = LockFreeStackIterator<LockFreeStack<Element, Tag>, false>

Definition at line 153 of file LockFreeStack.h.

◆ const_iterator

template<class Element, class Tag = void>
using beast::LockFreeStack< Element, Tag >::const_iterator = LockFreeStackIterator<LockFreeStack<Element, Tag>, true>

Definition at line 154 of file LockFreeStack.h.

Constructor & Destructor Documentation

◆ LockFreeStack() [1/2]

template<class Element, class Tag = void>
beast::LockFreeStack< Element, Tag >::LockFreeStack ( )

Definition at line 156 of file LockFreeStack.h.

◆ LockFreeStack() [2/2]

template<class Element, class Tag = void>
beast::LockFreeStack< Element, Tag >::LockFreeStack ( LockFreeStack< Element, Tag > const & )
delete

Member Function Documentation

◆ operator=()

template<class Element, class Tag = void>
LockFreeStack & beast::LockFreeStack< Element, Tag >::operator= ( LockFreeStack< Element, Tag > const & )
delete

◆ empty()

template<class Element, class Tag = void>
bool beast::LockFreeStack< Element, Tag >::empty ( ) const
nodiscard

Returns true if the stack is empty.

Definition at line 166 of file LockFreeStack.h.

◆ pushFront()

template<class Element, class Tag = void>
bool beast::LockFreeStack< Element, Tag >::pushFront ( Node * node)

Push a node onto the stack.

The caller is responsible for preventing the ABA problem. This operation is lock-free. Thread safety: Safe to call from any thread.

Parameters
nodeThe node to push.
Returns
true if the stack was previously empty. If multiple threads are attempting to push, only one will receive true.

Definition at line 184 of file LockFreeStack.h.

◆ popFront()

template<class Element, class Tag = void>
Element * beast::LockFreeStack< Element, Tag >::popFront ( )

Pop an element off the stack.

The caller is responsible for preventing the ABA problem. This operation is lock-free. Thread safety: Safe to call from any thread.

Returns
The element that was popped, or nullptr if the stack was empty.

Definition at line 207 of file LockFreeStack.h.

◆ begin() [1/2]

template<class Element, class Tag = void>
iterator beast::LockFreeStack< Element, Tag >::begin ( )

Return a forward iterator to the beginning or end of the stack.

Undefined behavior results if push_front or pop_front is called while an iteration is in progress. Thread safety: Caller is responsible for synchronization.

Definition at line 229 of file LockFreeStack.h.

◆ end() [1/2]

template<class Element, class Tag = void>
iterator beast::LockFreeStack< Element, Tag >::end ( )

Definition at line 235 of file LockFreeStack.h.

◆ begin() [2/2]

template<class Element, class Tag = void>
const_iterator beast::LockFreeStack< Element, Tag >::begin ( ) const
nodiscard

Definition at line 241 of file LockFreeStack.h.

◆ end() [2/2]

template<class Element, class Tag = void>
const_iterator beast::LockFreeStack< Element, Tag >::end ( ) const
nodiscard

Definition at line 247 of file LockFreeStack.h.

◆ cbegin()

template<class Element, class Tag = void>
const_iterator beast::LockFreeStack< Element, Tag >::cbegin ( ) const
nodiscard

Definition at line 253 of file LockFreeStack.h.

◆ cend()

template<class Element, class Tag = void>
const_iterator beast::LockFreeStack< Element, Tag >::cend ( ) const
nodiscard

Definition at line 259 of file LockFreeStack.h.

Member Data Documentation

◆ end_

template<class Element, class Tag = void>
Node beast::LockFreeStack< Element, Tag >::end_
private

Definition at line 266 of file LockFreeStack.h.

◆ head_

template<class Element, class Tag = void>
std::atomic<Node*> beast::LockFreeStack< Element, Tag >::head_
private

Definition at line 267 of file LockFreeStack.h.