proxygen
folly::hazptr_obj_linked< Atom > Class Template Reference

#include <Hazptr-fwd.h>

Inheritance diagram for folly::hazptr_obj_linked< Atom >:
folly::hazptr_obj< Atom > folly::hazptr_obj_base_linked< T, Atom, D > folly::hazptr_obj_base_linked< NodeAuto< Atom >, Atom > folly::hazptr_obj_base_linked< NodeRC< Mutable, Atom >, Atom > folly::hazptr_obj_base_linked< NodeT< KeyType, ValueType, Allocator, Atom >, Atom, concurrenthashmap::HazptrDeleter< Allocator > > folly::hazptr_obj_base_linked< Segment, Atom > NodeAuto< Atom > NodeRC< Mutable, Atom > folly::detail::concurrenthashmap::NodeT< KeyType, ValueType, Allocator, Atom > folly::UnboundedQueue< T, SingleProducer, SingleConsumer, MayBlock, LgSegmentSize, LgAlign, Atom >::Segment

Public Member Functions

void acquire_link () noexcept
 
void acquire_link_safe () noexcept
 
void acquire_ref () noexcept
 
void acquire_ref_safe () noexcept
 
- Public Member Functions inherited from folly::hazptr_obj< Atom >
 hazptr_obj () noexcept
 
 hazptr_obj (const hazptr_obj< Atom > &) noexcept
 
 hazptr_obj (hazptr_obj< Atom > &&) noexcept
 
hazptr_obj< Atom > & operator= (const hazptr_obj< Atom > &) noexcept
 
hazptr_obj< Atom > & operator= (hazptr_obj< Atom > &&) noexcept
 

Private Types

using Count = uint32_t
 

Private Member Functions

Count count () const noexcept
 
void count_set (Count val) noexcept
 
void count_inc (Count add) noexcept
 
void count_inc_safe (Count add) noexcept
 
bool count_cas (Count &oldval, Count newval) noexcept
 
bool release_link () noexcept
 
bool release_ref () noexcept
 
bool downgrade_link () noexcept
 

Private Attributes

Atom< Countcount_ {0}
 

Static Private Attributes

static constexpr Count kRef = 1u
 
static constexpr Count kLink = 1u << 16
 
static constexpr Count kRefMask = kLink - 1u
 
static constexpr Count kLinkMask = ~kRefMask
 

Friends

template<typename , template< typename > class, typename >
class hazptr_obj_base_linked
 

Detailed Description

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

hazptr_obj_linked

hazptr_obj_linked

Base class template for link counted objects. Supports:

  • Protecting descendants of protected objects.
  • One-pass reclamation of long immutable chains of objects.
  • Automatic reclamation of acyclic structures.

Two inbound link counts are maintained per object:

  • Link count: Represents the number of links from mutable paths.
  • Ref count: Represents the number of links from immutable paths. [Note: The ref count is one less than such links plus one if the object hasn't gone through matching with hazard pointers without finding a match. That is, a new object without inbound links has a ref count of 0 and an about-to-be-reclaimed object can be viewed to have a ref count of -1.]

User code can increment the link and ref counts by calling acquire_link and acquire_ref or their variants that require the user to guarantee thread safety. There are no public functions to decrement the counts explicitly. Counts are decremented implicitly as described in hazptr_obj_base_linked.

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

Member Typedef Documentation

template<template< typename > class Atom>
using folly::hazptr_obj_linked< Atom >::Count = uint32_t
private

Definition at line 92 of file HazptrObjLinked.h.

Member Function Documentation

template<template< typename > class Atom>
void folly::hazptr_obj_linked< Atom >::acquire_link ( )
inlinenoexcept

Definition at line 102 of file HazptrObjLinked.h.

102  {
103  count_inc(kLink);
104  }
void count_inc(Count add) noexcept
static constexpr Count kLink
template<template< typename > class Atom>
void folly::hazptr_obj_linked< Atom >::acquire_link_safe ( )
inlinenoexcept

Definition at line 106 of file HazptrObjLinked.h.

Referenced by auto_retire_test(), and basic_objects_test().

106  {
108  }
void count_inc_safe(Count add) noexcept
static constexpr Count kLink
template<template< typename > class Atom>
void folly::hazptr_obj_linked< Atom >::acquire_ref ( )
inlinenoexcept

Definition at line 110 of file HazptrObjLinked.h.

110  {
111  count_inc(kRef);
112  }
static constexpr Count kRef
void count_inc(Count add) noexcept
template<template< typename > class Atom>
void folly::hazptr_obj_linked< Atom >::acquire_ref_safe ( )
inlinenoexcept

Definition at line 114 of file HazptrObjLinked.h.

114  {
116  }
static constexpr Count kRef
void count_inc_safe(Count add) noexcept
template<template< typename > class Atom>
Count folly::hazptr_obj_linked< Atom >::count ( ) const
inlineprivatenoexcept

Definition at line 122 of file HazptrObjLinked.h.

122  {
123  return count_.load(std::memory_order_acquire);
124  }
template<template< typename > class Atom>
bool folly::hazptr_obj_linked< Atom >::count_cas ( Count oldval,
Count  newval 
)
inlineprivatenoexcept

Definition at line 143 of file HazptrObjLinked.h.

143  {
144  return count_.compare_exchange_weak(
145  oldval, newval, std::memory_order_acq_rel, std::memory_order_acquire);
146  }
template<template< typename > class Atom>
void folly::hazptr_obj_linked< Atom >::count_inc ( Count  add)
inlineprivatenoexcept

Definition at line 130 of file HazptrObjLinked.h.

References add.

130  {
131  auto oldval = count_.fetch_add(add, std::memory_order_acq_rel);
132  DCHECK_LT(oldval & kLinkMask, kLinkMask);
133  DCHECK_LT(oldval & kRefMask, kRefMask);
134  }
static constexpr Count kLinkMask
static constexpr Count kRefMask
template<template< typename > class Atom>
void folly::hazptr_obj_linked< Atom >::count_inc_safe ( Count  add)
inlineprivatenoexcept

Definition at line 136 of file HazptrObjLinked.h.

References add, and count.

136  {
137  auto oldval = count();
138  count_set(oldval + add);
139  DCHECK_LT(oldval & kLinkMask, kLinkMask);
140  DCHECK_LT(oldval & kRefMask, kRefMask);
141  }
static constexpr Count kLinkMask
Count count() const noexcept
static constexpr Count kRefMask
void count_set(Count val) noexcept
template<template< typename > class Atom>
void folly::hazptr_obj_linked< Atom >::count_set ( Count  val)
inlineprivatenoexcept

Definition at line 126 of file HazptrObjLinked.h.

References val.

126  {
127  count_.store(val, std::memory_order_release);
128  }
template<template< typename > class Atom>
bool folly::hazptr_obj_linked< Atom >::downgrade_link ( )
inlineprivatenoexcept

Definition at line 180 of file HazptrObjLinked.h.

References Atom, count, D, and folly::gen::sub().

180  {
181  auto oldval = count();
182  auto sub = kLink - kRef;
183  while (true) {
184  if (oldval == kLink) {
185  count_set(kRef);
186  return true;
187  }
188  if (count_cas(oldval, oldval - sub)) {
189  return (oldval & kLinkMask) == kLink;
190  }
191  }
192  }
Sub sub(Sink sink)
Definition: Parallel.h:104
static constexpr Count kRef
static constexpr Count kLinkMask
Count count() const noexcept
bool count_cas(Count &oldval, Count newval) noexcept
void count_set(Count val) noexcept
static constexpr Count kLink
template<template< typename > class Atom>
bool folly::hazptr_obj_linked< Atom >::release_link ( )
inlineprivatenoexcept

Definition at line 148 of file HazptrObjLinked.h.

References count, and folly::gen::sub().

148  {
149  auto sub = kLink;
150  auto oldval = count();
151  while (true) {
152  DCHECK_GT(oldval & kLinkMask, 0u);
153  if (oldval == kLink) {
154  count_set(0u);
155  return true;
156  }
157  if (count_cas(oldval, oldval - sub)) {
158  return false;
159  }
160  }
161  }
Sub sub(Sink sink)
Definition: Parallel.h:104
static constexpr Count kLinkMask
Count count() const noexcept
bool count_cas(Count &oldval, Count newval) noexcept
void count_set(Count val) noexcept
static constexpr Count kLink
template<template< typename > class Atom>
bool folly::hazptr_obj_linked< Atom >::release_ref ( )
inlineprivatenoexcept

Definition at line 163 of file HazptrObjLinked.h.

References count, folly::kIsDebug, and folly::gen::sub().

163  {
164  auto sub = kRef;
165  auto oldval = count();
166  while (true) {
167  if (oldval == 0u) {
168  if (kIsDebug) {
170  }
171  return true;
172  }
173  DCHECK_GT(oldval & kRefMask, 0u);
174  if (count_cas(oldval, oldval - sub)) {
175  return false;
176  }
177  }
178  }
Sub sub(Sink sink)
Definition: Parallel.h:104
static constexpr Count kRef
Count count() const noexcept
constexpr auto kIsDebug
Definition: Portability.h:264
bool count_cas(Count &oldval, Count newval) noexcept
static constexpr Count kRefMask
void count_set(Count val) noexcept

Friends And Related Function Documentation

template<template< typename > class Atom>
template<typename , template< typename > class, typename >
friend class hazptr_obj_base_linked
friend

Definition at line 120 of file HazptrObjLinked.h.

Member Data Documentation

template<template< typename > class Atom>
Atom<Count> folly::hazptr_obj_linked< Atom >::count_ {0}
private

Definition at line 99 of file HazptrObjLinked.h.

template<template< typename > class Atom>
constexpr Count folly::hazptr_obj_linked< Atom >::kLink = 1u << 16
staticprivate

Definition at line 95 of file HazptrObjLinked.h.

template<template< typename > class Atom>
constexpr Count folly::hazptr_obj_linked< Atom >::kLinkMask = ~kRefMask
staticprivate

Definition at line 97 of file HazptrObjLinked.h.

template<template< typename > class Atom>
constexpr Count folly::hazptr_obj_linked< Atom >::kRef = 1u
staticprivate

Definition at line 94 of file HazptrObjLinked.h.

template<template< typename > class Atom>
constexpr Count folly::hazptr_obj_linked< Atom >::kRefMask = kLink - 1u
staticprivate

Definition at line 96 of file HazptrObjLinked.h.


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