rippled
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
beast::LockFreeStack< Element, Tag > Class Template Reference

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

Collaboration diagram for beast::LockFreeStack< Element, Tag >:
Collaboration graph
[legend]

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. More...
 
bool push_front (Node *node)
 Push a node onto the stack. More...
 
Element * pop_front ()
 Pop an element off the stack. More...
 
iterator begin ()
 Return a forward iterator to the beginning or end of the stack. More...
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 

Private Attributes

Node m_end
 
std::atomic< Node * > m_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 146 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 174 of file LockFreeStack.h.

◆ pointer

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

Definition at line 175 of file LockFreeStack.h.

◆ reference

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

Definition at line 176 of file LockFreeStack.h.

◆ const_pointer

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

Definition at line 177 of file LockFreeStack.h.

◆ const_reference

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

Definition at line 178 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 179 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 180 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 181 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 183 of file LockFreeStack.h.

Constructor & Destructor Documentation

◆ LockFreeStack() [1/2]

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

Definition at line 185 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

Returns true if the stack is empty.

Definition at line 195 of file LockFreeStack.h.

◆ push_front()

template<class Element , class Tag = void>
bool beast::LockFreeStack< Element, Tag >::push_front ( 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 213 of file LockFreeStack.h.

◆ pop_front()

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

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 239 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 264 of file LockFreeStack.h.

◆ end() [1/2]

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

Definition at line 270 of file LockFreeStack.h.

◆ begin() [2/2]

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

Definition at line 276 of file LockFreeStack.h.

◆ end() [2/2]

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

Definition at line 282 of file LockFreeStack.h.

◆ cbegin()

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

Definition at line 288 of file LockFreeStack.h.

◆ cend()

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

Definition at line 294 of file LockFreeStack.h.

Member Data Documentation

◆ m_end

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

Definition at line 301 of file LockFreeStack.h.

◆ m_head

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

Definition at line 302 of file LockFreeStack.h.