proxygen
folly::DelayedDestructionBase::DestructorGuard Class Reference

#include <DelayedDestructionBase.h>

Inheritance diagram for folly::DelayedDestructionBase::DestructorGuard:
folly::DelayedDestructionBase::IntrusivePtr< AliasType >

Public Member Functions

 DestructorGuard (DelayedDestructionBase *dd)
 
 DestructorGuard (const DestructorGuard &dg)
 
 DestructorGuard (DestructorGuard &&dg) noexcept
 
DestructorGuardoperator= (DestructorGuard dg) noexcept
 
DestructorGuardoperator= (DelayedDestructionBase *dd)
 
 ~DestructorGuard ()
 
DelayedDestructionBaseget () const
 
 operator bool () const
 

Private Attributes

DelayedDestructionBasedd_
 

Detailed Description

Classes should create a DestructorGuard object on the stack in any function that may invoke callback functions.

The DestructorGuard prevents the guarded class from being destroyed while it exists. Without this, the callback function could delete the guarded object, causing problems when the callback function returns and the guarded object's method resumes execution.

Definition at line 62 of file DelayedDestructionBase.h.

Constructor & Destructor Documentation

folly::DelayedDestructionBase::DestructorGuard::DestructorGuard ( DelayedDestructionBase dd)
inlineexplicit

Definition at line 64 of file DelayedDestructionBase.h.

References dd_, and folly::DelayedDestructionBase::guardCount_.

Referenced by operator=().

64  : dd_(dd) {
65  if (dd_ != nullptr) {
66  ++dd_->guardCount_;
67  assert(dd_->guardCount_ > 0); // check for wrapping
68  }
69  }
folly::DelayedDestructionBase::DestructorGuard::DestructorGuard ( const DestructorGuard dg)
inline

Definition at line 71 of file DelayedDestructionBase.h.

71 : DestructorGuard(dg.dd_) {}
folly::DelayedDestructionBase::DestructorGuard::DestructorGuard ( DestructorGuard &&  dg)
inlinenoexcept

Definition at line 73 of file DelayedDestructionBase.h.

74  : dd_(std::exchange(dg.dd_, nullptr)) {}
T exchange(T &obj, U &&new_value)
Definition: Utility.h:120
folly::DelayedDestructionBase::DestructorGuard::~DestructorGuard ( )
inline

Definition at line 86 of file DelayedDestructionBase.h.

References dd_, folly::DelayedDestructionBase::guardCount_, and folly::DelayedDestructionBase::onDelayedDestroy().

86  {
87  if (dd_ != nullptr) {
88  assert(dd_->guardCount_ > 0);
89  --dd_->guardCount_;
90  if (dd_->guardCount_ == 0) {
91  dd_->onDelayedDestroy(true);
92  }
93  }
94  }
virtual void onDelayedDestroy(bool delayed)=0

Member Function Documentation

DelayedDestructionBase* folly::DelayedDestructionBase::DestructorGuard::get ( ) const
inline
folly::DelayedDestructionBase::DestructorGuard::operator bool ( ) const
inlineexplicit

Definition at line 100 of file DelayedDestructionBase.h.

References dd_.

100  {
101  return dd_ != nullptr;
102  }
DestructorGuard& folly::DelayedDestructionBase::DestructorGuard::operator= ( DestructorGuard  dg)
inlinenoexcept

Definition at line 76 of file DelayedDestructionBase.h.

References dd_, and folly::f14::swap().

Referenced by folly::DelayedDestructionBase::IntrusivePtr< AliasType >::IntrusivePtr(), and folly::DelayedDestructionBase::IntrusivePtr< AliasType >::operator=().

76  {
77  std::swap(dd_, dg.dd_);
78  return *this;
79  }
void swap(SwapTrackingAlloc< T > &, SwapTrackingAlloc< T > &)
Definition: F14TestUtil.h:414
DestructorGuard& folly::DelayedDestructionBase::DestructorGuard::operator= ( DelayedDestructionBase dd)
inline

Definition at line 81 of file DelayedDestructionBase.h.

References DestructorGuard().

81  {
82  *this = DestructorGuard(dd);
83  return *this;
84  }

Member Data Documentation

DelayedDestructionBase* folly::DelayedDestructionBase::DestructorGuard::dd_
private

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