proxygen
|
#include <DelayedDestructionBase.h>
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_ |
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:
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.
|
virtualdefault |
|
inlineprotected |
Definition at line 194 of file DelayedDestructionBase.h.
|
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().
|
protectedpure virtual |
Implement onDelayedDestroy in subclasses. onDelayedDestroy() is invoked when the object is potentially being destroyed.
delayed | This 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().
|
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().