proxygen
folly::DelayedDestructionBase Class Referenceabstract

#include <DelayedDestructionBase.h>

Inheritance diagram for folly::DelayedDestructionBase:
DestructionOnCallback folly::DelayedDestruction proxygen::HTTPTransaction DeleteGuarder fizz::client::test::TestFizzClient fizz::server::test::TestFizzServer fizz::test::TestFizzBase folly::AsyncPipeReader folly::AsyncPipeWriter folly::AsyncServerSocket folly::AsyncTransport folly::HHWheelTimer folly::NotificationQueue< MessageT >::Consumer proxygen::AsyncTimeoutSet wangle::AcceptorHandshakeHelper wangle::BroadcastPool< T, R, P >::BroadcastManager wangle::ConnectionManager wangle::ManagedConnection wangle::SocketPeeker proxygen::MockHTTPTransaction

Classes

class  DestructorGuard
 
class  IntrusivePtr
 

Public Member Functions

virtual ~DelayedDestructionBase ()=default
 

Protected Member Functions

 DelayedDestructionBase ()
 
uint32_t getDestructorGuardCount () const
 
virtual void onDelayedDestroy (bool delayed)=0
 

Private Attributes

uint32_t guardCount_
 

Detailed Description

DelayedDestructionBase is a helper class to ensure objects are not deleted while they still have functions executing in a higher stack frame.

This is useful for objects that invoke callback functions, to ensure that a callback does not destroy the calling object.

Classes needing this functionality should:

  • derive from DelayedDestructionBase directly
  • implement onDelayedDestroy which'll be called before the object is going to be destructed
  • create a DestructorGuard object on the stack in each public method that may invoke a callback

DelayedDestructionBase does not perform any locking. It is intended to be used only from a single thread.

Definition at line 49 of file DelayedDestructionBase.h.

Constructor & Destructor Documentation

virtual folly::DelayedDestructionBase::~DelayedDestructionBase ( )
virtualdefault
folly::DelayedDestructionBase::DelayedDestructionBase ( )
inlineprotected

Definition at line 194 of file DelayedDestructionBase.h.

Member Function Documentation

uint32_t folly::DelayedDestructionBase::getDestructorGuardCount ( ) const
inlineprotected

Get the number of DestructorGuards currently protecting this object.

This is primarily intended for debugging purposes, such as asserting that an object has at least 1 guard.

Definition at line 202 of file DelayedDestructionBase.h.

References guardCount_, and onDelayedDestroy().

Referenced by folly::DelayedDestruction::destroy(), folly::AsyncSocket::finishFail(), and folly::AsyncSocket::startFail().

202  {
203  return guardCount_;
204  }
virtual void folly::DelayedDestructionBase::onDelayedDestroy ( bool  delayed)
protectedpure virtual

Implement onDelayedDestroy in subclasses. onDelayedDestroy() is invoked when the object is potentially being destroyed.

Parameters
delayedThis parameter is true if destruction was delayed because of a DestructorGuard object, or false if onDelayedDestroy() is being called directly from the destructor.

Implemented in proxygen::HTTPTransaction, folly::DelayedDestruction, folly::UndelayedDestruction< HHWheelTimer >, and DestructionOnCallback.

Referenced by getDestructorGuardCount(), and folly::DelayedDestructionBase::DestructorGuard::~DestructorGuard().

Member Data Documentation

uint32_t folly::DelayedDestructionBase::guardCount_
private

guardCount_ is incremented by DestructorGuard, to indicate that one of the DelayedDestructionBase object's methods is currently running.

If the destructor is called while guardCount_ is non-zero, destruction will be delayed until guardCount_ drops to 0. This allows DelayedDestructionBase objects to invoke callbacks without having to worry about being deleted before the callback returns.

Definition at line 227 of file DelayedDestructionBase.h.

Referenced by folly::DelayedDestructionBase::DestructorGuard::DestructorGuard(), getDestructorGuardCount(), and folly::DelayedDestructionBase::DestructorGuard::~DestructorGuard().


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