proxygen
folly::hazptr_obj_base_linked< T, Atom, D > Class Template Reference

#include <Hazptr-fwd.h>

Inheritance diagram for folly::hazptr_obj_base_linked< T, Atom, D >:
folly::hazptr_obj_linked< Atom > folly::hazptr_deleter< T, D > folly::hazptr_obj< Atom >

Public Member Functions

void retire ()
 
void unlink ()
 
void unlink_and_reclaim_unchecked ()
 
- Public Member Functions inherited from folly::hazptr_obj_linked< Atom >
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
 
- Public Member Functions inherited from folly::hazptr_deleter< T, D >
void set_deleter (D d={})
 
void delete_obj (T *p)
 

Private Types

using Stack = std::stack< hazptr_obj_base_linked< T, Atom, D > * >
 

Private Member Functions

void set_reclaim () noexcept
 
void downgrade_retire_immutable_descendants ()
 
void release_delete_immutable_descendants ()
 
void release_retire_mutable_children (hazptr_obj_list< Atom > &l)
 
void call_push_links (bool m, Stack &s)
 
void delete_self ()
 

Detailed Description

template<typename T, template< typename > class Atom, typename D>
class folly::hazptr_obj_base_linked< T, Atom, D >

hazptr_obj_base_linked

hazptr_obj_base_linked

Base class template for link counted objects.

Supports both explicit and implicit object retirement, depending on whether object removal is certain or uncertain.

A derived object's removal is certain when it is always possible to reason based only on the local state of user code when an object is removed, i.e., becomes unreachable from static roots. Otherwise, removal is uncertain.

For example, Removal in UnboundedQueue is certain, whereas removal is ConcurrentHashMap is uncertain.

If removal is certain, user code can call retire() explicitly. Otherwise, user code should call unlink() whenever an inbound link to the object is changed. Calls to unlink() automatically retire the object when the link count is decremented to 0. [Note: A ref count greater than 0 does not delay retiring an object.]

Derived type T must define a member function template template <typename s>=""> void push_links(bool m, S& s) { if (m) { // m stands mutable links // for each outbound mutable pointer p call // s.push(p); } else { // for each outbound immutable pointer p call // s.push(p); } }

T may have both, either, or none of the two types of outbound links. For example, UnboundedQueue Segment has an immutable link, and ConcurrentHashMap NodeT has a mutable link.

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

Member Typedef Documentation

template<typename T, template< typename > class Atom, typename D>
using folly::hazptr_obj_base_linked< T, Atom, D >::Stack = std::stack<hazptr_obj_base_linked<T, Atom, D>*>
private

Definition at line 236 of file HazptrObjLinked.h.

Member Function Documentation

template<typename T, template< typename > class Atom, typename D>
void folly::hazptr_obj_base_linked< T, Atom, D >::call_push_links ( bool  m,
Stack s 
)
inlineprivate

Definition at line 317 of file HazptrObjLinked.h.

317  {
318  static_cast<T*>(this)->push_links(m, s); // to be defined in T
319  }
folly::std T
static map< string, int > m
static set< string > s
template<typename T, template< typename > class Atom, typename D>
void folly::hazptr_obj_base_linked< T, Atom, D >::delete_self ( )
inlineprivate

Definition at line 321 of file HazptrObjLinked.h.

321  {
322  this->delete_obj(static_cast<T*>(this)); // defined in hazptr_deleter
323  }
void delete_obj(T *p)
Definition: HazptrObj.h:204
template<typename T, template< typename > class Atom, typename D>
void folly::hazptr_obj_base_linked< T, Atom, D >::downgrade_retire_immutable_descendants ( )
inlineprivate

Definition at line 277 of file HazptrObjLinked.h.

277  {
278  Stack s;
279  call_push_links(false, s);
280  while (!s.empty()) {
281  auto p = s.top();
282  s.pop();
283  if (p && p->downgrade_link()) {
284  p->call_push_links(false, s);
285  p->retire();
286  }
287  }
288  }
std::stack< hazptr_obj_base_linked< T, Atom, D > * > Stack
static set< string > s
void call_push_links(bool m, Stack &s)
template<typename T, template< typename > class Atom, typename D>
void folly::hazptr_obj_base_linked< T, Atom, D >::release_delete_immutable_descendants ( )
inlineprivate

Definition at line 290 of file HazptrObjLinked.h.

Referenced by folly::hazptr_obj_base_linked< NodeAuto< Atom >, Atom >::set_reclaim().

290  {
291  Stack s;
292  call_push_links(false, s);
293  while (!s.empty()) {
294  auto p = s.top();
295  s.pop();
296  if (p && p->release_ref()) {
297  p->call_push_links(false, s);
298  p->delete_self();
299  }
300  }
301  }
std::stack< hazptr_obj_base_linked< T, Atom, D > * > Stack
static set< string > s
void call_push_links(bool m, Stack &s)
template<typename T, template< typename > class Atom, typename D>
void folly::hazptr_obj_base_linked< T, Atom, D >::release_retire_mutable_children ( hazptr_obj_list< Atom > &  l)
inlineprivate

Definition at line 303 of file HazptrObjLinked.h.

303  {
304  Stack s;
305  call_push_links(true, s);
306  while (!s.empty()) {
307  auto p = s.top();
308  s.pop();
309  if (p->release_link()) {
310  p->pre_retire_check(); // defined in hazptr_obj
311  p->set_reclaim();
312  l.push(p); // treated as if retired immediately
313  }
314  }
315  }
std::stack< hazptr_obj_base_linked< T, Atom, D > * > Stack
static set< string > s
void call_push_links(bool m, Stack &s)
template<typename T, template< typename > class Atom, typename D>
void folly::hazptr_obj_base_linked< T, Atom, D >::retire ( )
inline

Definition at line 239 of file HazptrObjLinked.h.

Referenced by basic_objects_test().

239  {
240  this->pre_retire_check(); // defined in hazptr_obj
241  set_reclaim();
242  this->push_to_retired(
243  default_hazptr_domain<Atom>()); // defined in hazptr_obj
244  }
void pre_retire_check() noexcept
Definition: HazptrObj.h:102
void push_to_retired(hazptr_domain< Atom > &domain)
Definition: HazptrObj.h:109
template<typename T, template< typename > class Atom, typename D>
void folly::hazptr_obj_base_linked< T, Atom, D >::set_reclaim ( )
inlineprivatenoexcept

Definition at line 266 of file HazptrObjLinked.h.

266  {
267  this->reclaim_ = [](hazptr_obj<Atom>* p, hazptr_obj_list<Atom>& l) {
268  auto obj = static_cast<hazptr_obj_base_linked<T, Atom, D>*>(p);
269  if (obj->release_ref()) { // defined in hazptr_obj_linked
270  obj->release_delete_immutable_descendants();
271  obj->release_retire_mutable_children(l);
272  obj->delete_self();
273  }
274  };
275  }
ReclaimFnPtr reclaim_
Definition: HazptrObj.h:54
template<typename T, template< typename > class Atom, typename D>
void folly::hazptr_obj_base_linked< T, Atom, D >::unlink ( )
inline

Definition at line 247 of file HazptrObjLinked.h.

247  {
248  if (this->release_link()) { // defined in hazptr_obj_linked
250  retire();
251  }
252  }
bool release_link() noexcept
template<typename T, template< typename > class Atom, typename D>
void folly::hazptr_obj_base_linked< T, Atom, D >::unlink_and_reclaim_unchecked ( )
inline

Definition at line 258 of file HazptrObjLinked.h.

258  {
259  if (this->release_link()) { // defined in hazptr_obj_linked
260  DCHECK_EQ(this->count(), 0u);
261  delete_self();
262  }
263  }
Count count() const noexcept
bool release_link() noexcept

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