proxygen
List< T, Atom > Struct Template Reference

Public Member Functions

 List (int size)
 
 ~List ()
 
bool hand_over_hand (int val, hazptr_holder< Atom > *hptr_prev, hazptr_holder< Atom > *hptr_curr)
 
bool hand_over_hand (int val)
 
bool protect_all (int val, hazptr_holder< Atom > &hptr)
 
bool protect_all (int val)
 

Public Attributes

Atom< T * > head_ {nullptr}
 

Detailed Description

template<typename T, template< typename > class Atom = std::atomic>
struct List< T, Atom >

List

Definition at line 170 of file HazptrTest.cpp.

Constructor & Destructor Documentation

template<typename T, template< typename > class Atom = std::atomic>
List< T, Atom >::List ( int  size)
inlineexplicit

Definition at line 174 of file HazptrTest.cpp.

References i, and T.

174  {
175  auto p = head_.load(std::memory_order_relaxed);
176  for (int i = 0; i < size - 1; ++i) {
177  p = new T(i + 10000, p, true);
178  }
179  p = new T(size + 9999, p);
180  head_.store(p, std::memory_order_relaxed);
181  }
#define T(v)
Definition: http_parser.c:233
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
Atom< T * > head_
Definition: HazptrTest.cpp:171
template<typename T, template< typename > class Atom = std::atomic>
List< T, Atom >::~List ( )
inline

Definition at line 183 of file HazptrTest.cpp.

References cpp.ast::next().

183  {
184  auto curr = head_.load(std::memory_order_relaxed);
185  while (curr) {
186  auto next = curr->next();
187  curr->retire();
188  curr = next;
189  }
190  }
Atom< T * > head_
Definition: HazptrTest.cpp:171
def next(obj)
Definition: ast.py:58

Member Function Documentation

template<typename T, template< typename > class Atom = std::atomic>
bool List< T, Atom >::hand_over_hand ( int  val,
hazptr_holder< Atom > *  hptr_prev,
hazptr_holder< Atom > *  hptr_curr 
)
inline

Definition at line 192 of file HazptrTest.cpp.

References cpp.ast::next(), folly::f14::swap(), folly::hazptr_holder< Atom >::try_protect(), and val.

Referenced by list_hoh_bench().

195  {
196  while (true) {
197  auto prev = &head_;
198  auto curr = prev->load(std::memory_order_acquire);
199  while (true) {
200  if (!curr) {
201  return false;
202  }
203  if (!hptr_curr->try_protect(curr, *prev)) {
204  break;
205  }
206  auto next = curr->next();
207  if (prev->load(std::memory_order_acquire) != curr) {
208  break;
209  }
210  if (curr->value() == val) {
211  return true;
212  }
213  prev = curr->ptr_next();
214  curr = next;
215  std::swap(hptr_curr, hptr_prev);
216  }
217  }
218  }
FOLLY_ALWAYS_INLINE bool try_protect(T *&ptr, const Atom< T * > &src) noexcept
Definition: HazptrHolder.h:116
double val
Definition: String.cpp:273
Atom< T * > head_
Definition: HazptrTest.cpp:171
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414
def next(obj)
Definition: ast.py:58
template<typename T, template< typename > class Atom = std::atomic>
bool List< T, Atom >::hand_over_hand ( int  val)
inline

Definition at line 220 of file HazptrTest.cpp.

220  {
222  return hand_over_hand(val, &hptr[0], &hptr[1]);
223  }
bool hand_over_hand(int val, hazptr_holder< Atom > *hptr_prev, hazptr_holder< Atom > *hptr_curr)
Definition: HazptrTest.cpp:192
double val
Definition: String.cpp:273
template<typename T, template< typename > class Atom = std::atomic>
bool List< T, Atom >::protect_all ( int  val,
hazptr_holder< Atom > &  hptr 
)
inline

Definition at line 225 of file HazptrTest.cpp.

References folly::hazptr_holder< Atom >::get_protected(), cpp.ast::next(), and val.

Referenced by list_protect_all_bench().

225  {
226  auto curr = hptr.get_protected(head_);
227  while (curr) {
228  auto next = curr->next();
229  if (curr->value() == val) {
230  return true;
231  }
232  curr = next;
233  }
234  return false;
235  }
FOLLY_ALWAYS_INLINE T * get_protected(const Atom< T * > &src) noexcept
Definition: HazptrHolder.h:138
double val
Definition: String.cpp:273
Atom< T * > head_
Definition: HazptrTest.cpp:171
def next(obj)
Definition: ast.py:58
template<typename T, template< typename > class Atom = std::atomic>
bool List< T, Atom >::protect_all ( int  val)
inline

Definition at line 237 of file HazptrTest.cpp.

References Atom.

237  {
239  return protect_all(val, hptr[0]);
240  }
bool protect_all(int val, hazptr_holder< Atom > &hptr)
Definition: HazptrTest.cpp:225
double val
Definition: String.cpp:273

Member Data Documentation

template<typename T, template< typename > class Atom = std::atomic>
Atom<T*> List< T, Atom >::head_ {nullptr}

Definition at line 171 of file HazptrTest.cpp.


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