proxygen
folly::hazptr_holder< Atom > Class Template Reference

#include <Hazptr-fwd.h>

Public Member Functions

FOLLY_ALWAYS_INLINE hazptr_holder (hazptr_domain< Atom > &domain=default_hazptr_domain< Atom >())
 
FOLLY_ALWAYS_INLINE hazptr_holder (std::nullptr_t) noexcept
 
FOLLY_ALWAYS_INLINE hazptr_holder (hazptr_holder &&rhs) noexcept
 
 hazptr_holder (const hazptr_holder &)=delete
 
hazptr_holderoperator= (const hazptr_holder &)=delete
 
FOLLY_ALWAYS_INLINE ~hazptr_holder ()
 
FOLLY_ALWAYS_INLINE hazptr_holderoperator= (hazptr_holder &&rhs) noexcept
 
template<typename T >
FOLLY_ALWAYS_INLINE bool try_protect (T *&ptr, const Atom< T * > &src) noexcept
 
template<typename T , typename Func >
FOLLY_ALWAYS_INLINE bool try_protect (T *&ptr, const Atom< T * > &src, Func f) noexcept
 
template<typename T >
FOLLY_ALWAYS_INLINE Tget_protected (const Atom< T * > &src) noexcept
 
template<typename T , typename Func >
FOLLY_ALWAYS_INLINE Tget_protected (const Atom< T * > &src, Func f) noexcept
 
template<typename T >
FOLLY_ALWAYS_INLINE void reset (const T *ptr) noexcept
 
FOLLY_ALWAYS_INLINE void reset (std::nullptr_t=nullptr) noexcept
 
FOLLY_ALWAYS_INLINE void swap (hazptr_holder< Atom > &rhs) noexcept
 
FOLLY_ALWAYS_INLINE hazptr_rec< Atom > * hprec () const noexcept
 
FOLLY_ALWAYS_INLINE void set_hprec (hazptr_rec< Atom > *hprec) noexcept
 

Private Attributes

hazptr_rec< Atom > * hprec_
 

Detailed Description

template<template< typename > class Atom>
class folly::hazptr_holder< Atom >

Classes related to hazard pointer holders. Defined in HazptrHolder.hhazptr_holder

Classes related to hazard pointer holders. hazptr_holder

Class for automatic acquisition and release of hazard pointers, and interface for hazard pointer operations.

Usage example: T* ptr; { hazptr_holder h; ptr = h.get_protected(src); // ... *ptr is protected ... h.reset(); // ... *ptr is not protected ... ptr = src.load(); while (!h.try_protect(ptr, src)) {} // ... *ptr is protected ... } // ... *ptr is not protected

Definition at line 155 of file Hazptr-fwd.h.

Constructor & Destructor Documentation

template<template< typename > class Atom>
FOLLY_ALWAYS_INLINE folly::hazptr_holder< Atom >::hazptr_holder ( hazptr_domain< Atom > &  domain = default_hazptr_domain<Atom>())
inlineexplicit

Constructor - automatically acquires a hazard pointer.

Definition at line 57 of file HazptrHolder.h.

References folly::hazptr_holder< Atom >::hprec(), and LIKELY.

Referenced by folly::hazptr_holder< Atom >::hazptr_holder(), and folly::hazptr_holder< Atom >::operator=().

58  {
59 #if FOLLY_HAZPTR_THR_LOCAL
60  if (LIKELY(&domain == &default_hazptr_domain<Atom>())) {
61  auto hprec = hazptr_tc_tls<Atom>().try_get();
62  if (LIKELY(hprec != nullptr)) {
63  hprec_ = hprec;
64  return;
65  }
66  }
67 #endif
68  hprec_ = domain.hprec_acquire();
69  }
#define LIKELY(x)
Definition: Likely.h:47
hazptr_rec< Atom > * hprec_
Definition: HazptrHolder.h:53
FOLLY_ALWAYS_INLINE hazptr_rec< Atom > * hprec() const noexcept
Definition: HazptrHolder.h:173
template<template< typename > class Atom>
FOLLY_ALWAYS_INLINE folly::hazptr_holder< Atom >::hazptr_holder ( std::nullptr_t  )
inlineexplicitnoexcept

Empty constructor

Definition at line 72 of file HazptrHolder.h.

73  : hprec_(nullptr) {}
hazptr_rec< Atom > * hprec_
Definition: HazptrHolder.h:53
template<template< typename > class Atom>
FOLLY_ALWAYS_INLINE folly::hazptr_holder< Atom >::hazptr_holder ( hazptr_holder< Atom > &&  rhs)
inlinenoexcept

Move constructor

Definition at line 76 of file HazptrHolder.h.

References folly::hazptr_holder< Atom >::hazptr_holder(), folly::hazptr_holder< Atom >::operator=(), and folly::detail::rhs.

76  {
77  hprec_ = rhs.hprec_;
78  rhs.hprec_ = nullptr;
79  }
hazptr_rec< Atom > * hprec_
Definition: HazptrHolder.h:53
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
template<template< typename > class Atom>
folly::hazptr_holder< Atom >::hazptr_holder ( const hazptr_holder< Atom > &  )
delete
template<template< typename > class Atom>
FOLLY_ALWAYS_INLINE folly::hazptr_holder< Atom >::~hazptr_holder ( )
inline

Destructor

Definition at line 85 of file HazptrHolder.h.

References folly::hazptr_rec< Atom >::domain(), LIKELY, and folly::hazptr_rec< Atom >::reset_hazptr().

Referenced by folly::hazptr_holder< Atom >::operator=().

85  {
86  if (LIKELY(hprec_ != nullptr)) {
87  hprec_->reset_hazptr();
88  auto domain = hprec_->domain();
89 #if FOLLY_HAZPTR_THR_LOCAL
90  if (LIKELY(domain == &default_hazptr_domain<Atom>())) {
91  if (LIKELY(hazptr_tc_tls<Atom>().try_put(hprec_))) {
92  return;
93  }
94  }
95 #endif
96  domain->hprec_release(hprec_);
97  }
98  }
#define LIKELY(x)
Definition: Likely.h:47
hazptr_rec< Atom > * hprec_
Definition: HazptrHolder.h:53

Member Function Documentation

template<template< typename > class Atom>
template<typename T , typename Func >
FOLLY_ALWAYS_INLINE T* folly::hazptr_holder< Atom >::get_protected ( const Atom< T * > &  src,
Func  f 
)
inlinenoexcept

Definition at line 143 of file HazptrHolder.h.

References f, ptr, folly::T, and folly::hazptr_holder< Atom >::try_protect().

143  {
144  T* ptr = src.load(std::memory_order_relaxed);
145  while (!try_protect(ptr, src, f)) {
146  /* Keep trying */;
147  }
148  return ptr;
149  }
void * ptr
auto f
FOLLY_ALWAYS_INLINE bool try_protect(T *&ptr, const Atom< T * > &src) noexcept
Definition: HazptrHolder.h:116
folly::std T
template<template< typename > class Atom>
FOLLY_ALWAYS_INLINE hazptr_holder& folly::hazptr_holder< Atom >::operator= ( hazptr_holder< Atom > &&  rhs)
inlinenoexcept

Move operator

Definition at line 101 of file HazptrHolder.h.

References folly::hazptr_holder< Atom >::hazptr_holder(), LIKELY, folly::detail::rhs, and folly::hazptr_holder< Atom >::~hazptr_holder().

101  {
102  /* Self-move is a no-op. */
103  if (LIKELY(this != &rhs)) {
104  this->~hazptr_holder();
105  new (this) hazptr_holder(nullptr);
106  hprec_ = rhs.hprec_;
107  rhs.hprec_ = nullptr;
108  }
109  return *this;
110  }
#define LIKELY(x)
Definition: Likely.h:47
hazptr_rec< Atom > * hprec_
Definition: HazptrHolder.h:53
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
FOLLY_ALWAYS_INLINE ~hazptr_holder()
Definition: HazptrHolder.h:85
FOLLY_ALWAYS_INLINE hazptr_holder(hazptr_domain< Atom > &domain=default_hazptr_domain< Atom >())
Definition: HazptrHolder.h:57
template<template< typename > class Atom>
template<typename T >
FOLLY_ALWAYS_INLINE void folly::hazptr_holder< Atom >::reset ( const T ptr)
inlinenoexcept

reset

Definition at line 153 of file HazptrHolder.h.

References ptr, folly::hazptr_rec< Atom >::reset_hazptr(), and folly::T.

Referenced by basic_protection_test(), folly::HazptrWideCAS< T, Atom >::cas(), move_test(), folly::HazptrLockFreeLIFO< T, Atom >::pop(), folly::hazptr_holder< Atom >::try_protect(), and virtual_test().

153  {
154  auto p = static_cast<hazptr_obj<Atom>*>(const_cast<T*>(ptr));
155  DCHECK(hprec_); // UB if *this is empty
156  hprec_->reset_hazptr(p);
157  }
void * ptr
folly::std T
hazptr_rec< Atom > * hprec_
Definition: HazptrHolder.h:53
template<template< typename > class Atom>
FOLLY_ALWAYS_INLINE void folly::hazptr_holder< Atom >::reset ( std::nullptr_t  = nullptr)
inlinenoexcept

Definition at line 159 of file HazptrHolder.h.

References folly::hazptr_rec< Atom >::reset_hazptr().

159  {
160  DCHECK(hprec_); // UB if *this is empty
161  hprec_->reset_hazptr();
162  }
hazptr_rec< Atom > * hprec_
Definition: HazptrHolder.h:53
template<template< typename > class Atom>
FOLLY_ALWAYS_INLINE void folly::hazptr_holder< Atom >::set_hprec ( hazptr_rec< Atom > *  hprec)
inlinenoexcept

Set the pointer to the owned hazptr_rec

Definition at line 178 of file HazptrHolder.h.

References Atom, and folly::hazptr_holder< Atom >::hprec().

178  {
179  hprec_ = hprec;
180  }
hazptr_rec< Atom > * hprec_
Definition: HazptrHolder.h:53
FOLLY_ALWAYS_INLINE hazptr_rec< Atom > * hprec() const noexcept
Definition: HazptrHolder.h:173
template<template< typename > class Atom>
FOLLY_ALWAYS_INLINE void folly::hazptr_holder< Atom >::swap ( hazptr_holder< Atom > &  rhs)
inlinenoexcept

Definition at line 168 of file HazptrHolder.h.

References folly::detail::rhs, and folly::swap().

168  {
169  std::swap(this->hprec_, rhs.hprec_);
170  }
hazptr_rec< Atom > * hprec_
Definition: HazptrHolder.h:53
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
FOLLY_ALWAYS_INLINE void swap(hazptr_holder< Atom > &lhs, hazptr_holder< Atom > &rhs) noexcept
Definition: HazptrHolder.h:187
template<template< typename > class Atom>
template<typename T >
FOLLY_ALWAYS_INLINE bool folly::hazptr_holder< Atom >::try_protect ( T *&  ptr,
const Atom< T * > &  src 
)
inlinenoexcept

Hazard pointer operations try_protect

Definition at line 116 of file HazptrHolder.h.

References FOLLY_ALWAYS_INLINE, ptr, folly::pushmi::detail::t, and folly::T.

Referenced by folly::HazptrSWMRSet< T, Atom >::contains(), folly::hazptr_holder< Atom >::get_protected(), and List< T, Atom >::hand_over_hand().

116  {
117  return try_protect(ptr, src, [](T* t) { return t; });
118  }
void * ptr
FOLLY_ALWAYS_INLINE bool try_protect(T *&ptr, const Atom< T * > &src) noexcept
Definition: HazptrHolder.h:116
folly::std T
template<template< typename > class Atom>
template<typename T , typename Func >
FOLLY_ALWAYS_INLINE bool folly::hazptr_holder< Atom >::try_protect ( T *&  ptr,
const Atom< T * > &  src,
Func  f 
)
inlinenoexcept

Definition at line 122 of file HazptrHolder.h.

References folly::asymmetricLightBarrier(), f, ptr, folly::hazptr_holder< Atom >::reset(), and UNLIKELY.

122  {
123  /* Filtering the protected pointer through function Func is useful
124  for stealing bits of the pointer word */
125  auto p = ptr;
126  reset(f(p));
127  /*** Full fence ***/ folly::asymmetricLightBarrier();
128  ptr = src.load(std::memory_order_acquire);
129  if (UNLIKELY(p != ptr)) {
130  reset();
131  return false;
132  }
133  return true;
134  }
void * ptr
auto f
FOLLY_ALWAYS_INLINE void asymmetricLightBarrier()
FOLLY_ALWAYS_INLINE void reset(const T *ptr) noexcept
Definition: HazptrHolder.h:153
#define UNLIKELY(x)
Definition: Likely.h:48

Member Data Documentation

template<template< typename > class Atom>
hazptr_rec<Atom>* folly::hazptr_holder< Atom >::hprec_
private

Definition at line 53 of file HazptrHolder.h.

Referenced by folly::hazptr_holder< Atom >::hprec().


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