proxygen
|
#include <DelayedDestruction.h>
Classes | |
class | Destructor |
Public Member Functions | |
virtual void | destroy () |
bool | getDestroyPending () const |
Public Member Functions inherited from folly::DelayedDestructionBase | |
virtual | ~DelayedDestructionBase ()=default |
Protected Member Functions | |
~DelayedDestruction () override=default | |
DelayedDestruction () | |
Protected Member Functions inherited from folly::DelayedDestructionBase | |
DelayedDestructionBase () | |
uint32_t | getDestructorGuardCount () const |
Private Member Functions | |
void | onDelayedDestroy (bool delayed) override |
Private Attributes | |
bool | destroyPending_ |
DelayedDestruction 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:
DelayedDestruction does not perform any locking. It is intended to be used only from a single thread.
Definition at line 42 of file DelayedDestruction.h.
|
overrideprotecteddefault |
Protected destructor.
Making this protected ensures that users cannot delete DelayedDestruction objects directly, and that everyone must use destroy() instead. Subclasses of DelayedDestruction must also define their destructors as protected or private in order for this to work.
This also means that DelayedDestruction objects cannot be created directly on the stack; they must always be dynamically allocated on the heap.
In order to use a DelayedDestruction object with a shared_ptr, create the shared_ptr using a DelayedDestruction::Destructor as the second argument to the shared_ptr constructor.
Referenced by getDestroyPending().
|
inlineprotected |
Definition at line 99 of file DelayedDestruction.h.
|
inlinevirtual |
destroy() requests destruction of the object.
This method will destroy the object after it has no more functions running higher up on the stack. (i.e., No more DestructorGuard objects exist for this object.) This method must be used instead of the destructor.
Reimplemented in folly::AsyncSocket, folly::AsyncServerSocket, folly::NotificationQueue< MessageT >::Consumer, proxygen::AsyncTimeoutSet, fizz::AsyncFizzBase, and folly::UndelayedDestruction< HHWheelTimer >.
Definition at line 51 of file DelayedDestruction.h.
References destroyPending_, folly::DelayedDestructionBase::getDestructorGuardCount(), and onDelayedDestroy().
Referenced by proxygen::HTTPSession::checkForShutdown(), folly::NotificationQueue< MessageT >::Consumer::destroy(), folly::AsyncServerSocket::destroy(), folly::AsyncSocket::destroy(), and folly::DelayedDestruction::Destructor::operator()().
|
inline |
Definition at line 76 of file DelayedDestruction.h.
References destroyPending_, and ~DelayedDestruction().
|
inlineoverrideprivatevirtual |
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. |
Implements folly::DelayedDestructionBase.
Reimplemented in folly::UndelayedDestruction< HHWheelTimer >.
Definition at line 111 of file DelayedDestruction.h.
Referenced by destroy().
|
private |
destroyPending_ is set to true if destoy() is called while guardCount_ is non-zero. It is set to false before the object is deleted.
If destroyPending_ is true, the object will be destroyed the next time guardCount_ drops to 0.
Definition at line 109 of file DelayedDestruction.h.
Referenced by destroy(), and getDestroyPending().