proxygen
folly::HazptrLockFreeLIFO< T, Atom > Class Template Reference

#include <HazptrLockFreeLIFO.h>

Classes

struct  Node
 

Public Member Functions

 HazptrLockFreeLIFO ()
 
 ~HazptrLockFreeLIFO ()
 
void push (T val)
 
bool pop (T &val)
 

Private Member Functions

Nodehead ()
 
bool cas_head (Node *&expected, Node *newval)
 

Private Attributes

Atom< Node * > head_
 

Detailed Description

template<typename T, template< typename > class Atom = std::atomic>
class folly::HazptrLockFreeLIFO< T, Atom >

Definition at line 23 of file HazptrLockFreeLIFO.h.

Constructor & Destructor Documentation

template<typename T, template< typename > class Atom = std::atomic>
folly::HazptrLockFreeLIFO< T, Atom >::HazptrLockFreeLIFO ( )
inline

Definition at line 29 of file HazptrLockFreeLIFO.h.

29 : head_(nullptr) {}
template<typename T, template< typename > class Atom = std::atomic>
folly::HazptrLockFreeLIFO< T, Atom >::~HazptrLockFreeLIFO ( )
inline

Definition at line 31 of file HazptrLockFreeLIFO.h.

References folly::HazptrLockFreeLIFO< T, Atom >::head(), cpp.ast::next(), folly::HazptrLockFreeLIFO< T, Atom >::Node::next(), and folly::hazptr_obj_base< T, Atom, D >::retire().

31  {
32  Node* next;
33  for (auto node = head(); node; node = next) {
34  next = node->next();
35  node->retire();
36  }
37  hazptr_cleanup<Atom>();
38  }
Node< Atom > * next() const noexcept
Definition: HazptrTest.cpp:116
def next(obj)
Definition: ast.py:58

Member Function Documentation

template<typename T, template< typename > class Atom = std::atomic>
bool folly::HazptrLockFreeLIFO< T, Atom >::cas_head ( Node *&  expected,
Node newval 
)
inlineprivate

Definition at line 72 of file HazptrLockFreeLIFO.h.

Referenced by folly::HazptrLockFreeLIFO< T, Atom >::pop(), and folly::HazptrLockFreeLIFO< T, Atom >::push().

72  {
73  return head_.compare_exchange_weak(
74  expected, newval, std::memory_order_acq_rel, std::memory_order_acquire);
75  }
template<typename T, template< typename > class Atom = std::atomic>
Node* folly::HazptrLockFreeLIFO< T, Atom >::head ( )
inlineprivate

Definition at line 68 of file HazptrLockFreeLIFO.h.

Referenced by folly::HazptrLockFreeLIFO< T, Atom >::push(), and folly::HazptrLockFreeLIFO< T, Atom >::~HazptrLockFreeLIFO().

68  {
69  return head_.load(std::memory_order_acquire);
70  }
template<typename T, template< typename > class Atom = std::atomic>
bool folly::HazptrLockFreeLIFO< T, Atom >::pop ( T val)
inline

Definition at line 47 of file HazptrLockFreeLIFO.h.

References folly::HazptrLockFreeLIFO< T, Atom >::cas_head(), folly::hazptr_holder< Atom >::get_protected(), h, cpp.ast::next(), folly::HazptrLockFreeLIFO< T, Atom >::Node::next(), folly::hazptr_holder< Atom >::reset(), folly::hazptr_obj_base< T, Atom, D >::retire(), and folly::HazptrLockFreeLIFO< T, Atom >::Node::value().

Referenced by lifo_test().

47  {
48  hazptr_local<1, Atom> h;
49  hazptr_holder<Atom>& hptr = h[0];
50  Node* node;
51  while (true) {
52  node = hptr.get_protected(head_);
53  if (node == nullptr) {
54  return false;
55  }
56  auto next = node->next();
57  if (cas_head(node, next)) {
58  break;
59  }
60  }
61  hptr.reset();
62  val = node->value();
63  node->retire();
64  return true;
65  }
bool cas_head(Node *&expected, Node *newval)
*than *hazptr_holder h
Definition: Hazptr.h:116
void retire(D deleter={}, hazptr_domain< Atom > &domain=default_hazptr_domain< Atom >())
Definition: HazptrObj.h:229
double val
Definition: String.cpp:273
int value() const noexcept
Definition: HazptrTest.cpp:112
Node< Atom > * next() const noexcept
Definition: HazptrTest.cpp:116
def next(obj)
Definition: ast.py:58
template<typename T, template< typename > class Atom = std::atomic>
void folly::HazptrLockFreeLIFO< T, Atom >::push ( T  val)
inline

Definition at line 40 of file HazptrLockFreeLIFO.h.

References folly::HazptrLockFreeLIFO< T, Atom >::cas_head(), folly::HazptrLockFreeLIFO< T, Atom >::head(), and Node< Atom >::Node().

Referenced by lifo_test().

40  {
41  auto node = new Node(val, head());
42  while (!cas_head(node->next_, node)) {
43  /* try again */;
44  }
45  }
bool cas_head(Node *&expected, Node *newval)
double val
Definition: String.cpp:273

Member Data Documentation

template<typename T, template< typename > class Atom = std::atomic>
Atom<Node*> folly::HazptrLockFreeLIFO< T, Atom >::head_
private

Definition at line 24 of file HazptrLockFreeLIFO.h.


The documentation for this class was generated from the following file: