proxygen
folly::UndelayedDestruction< TDD > Class Template Reference

#include <UndelayedDestruction.h>

Inheritance diagram for folly::UndelayedDestruction< TDD >:

Public Member Functions

template<typename... Args>
 UndelayedDestruction (Args &&...args)
 
 ~UndelayedDestruction () override
 
void onDelayedDestroy (bool delayed) override
 

Protected Member Functions

void destroy () override
 

Private Member Functions

 UndelayedDestruction (UndelayedDestruction const &)=delete
 
UndelayedDestructionoperator= (UndelayedDestruction const &)=delete
 

Detailed Description

template<typename TDD>
class folly::UndelayedDestruction< TDD >

A helper class to allow a DelayedDestruction object to be instantiated on the stack.

This class derives from an existing DelayedDestruction type and makes the destructor public again. This allows objects of this type to be declared on the stack or directly inside another class. Normally DelayedDestruction objects must be dynamically allocated on the heap.

However, the trade-off is that you lose some of the protections provided by DelayedDestruction::destroy(). DelayedDestruction::destroy() will automatically delay destruction of the object until it is safe to do so. If you use UndelayedDestruction, you become responsible for ensuring that you only destroy the object where it is safe to do so. Attempting to destroy a UndelayedDestruction object while it has a non-zero destructor guard count will abort the program.

Definition at line 44 of file UndelayedDestruction.h.

Constructor & Destructor Documentation

template<typename TDD>
template<typename... Args>
folly::UndelayedDestruction< TDD >::UndelayedDestruction ( Args &&...  args)
inlineexplicit

Definition at line 57 of file UndelayedDestruction.h.

Referenced by folly::UndelayedDestruction< HHWheelTimer >::destroy().

58  : TDD(std::forward<Args>(args)...) {}
template<typename TDD>
folly::UndelayedDestruction< TDD >::~UndelayedDestruction ( )
inlineoverride

Public destructor.

The caller is responsible for ensuring that the object is only destroyed where it is safe to do so. (i.e., when the destructor guard count is 0).

The exact conditions for meeting this may be dependent upon your class semantics. Typically you are only guaranteed that it is safe to destroy the object directly from the event loop (e.g., directly from a EventBase::LoopCallback), or when the event loop is stopped.

Definition at line 71 of file UndelayedDestruction.h.

71  {
72  // Crash if the caller is destroying us with outstanding destructor guards.
73  if (this->getDestructorGuardCount() != 0) {
74  abort();
75  }
76  // Invoke destroy. This is necessary since our base class may have
77  // implemented custom behavior in destroy().
78  this->destroy();
79  }
template<typename TDD>
folly::UndelayedDestruction< TDD >::UndelayedDestruction ( UndelayedDestruction< TDD > const &  )
privatedelete

Member Function Documentation

template<typename TDD>
void folly::UndelayedDestruction< TDD >::destroy ( )
inlineoverrideprotected

Override our parent's destroy() method to make it protected. Callers should use the normal destructor instead of destroy

Definition at line 97 of file UndelayedDestruction.h.

Referenced by folly::UndelayedDestruction< HHWheelTimer >::~UndelayedDestruction().

97  {
98  this->TDD::destroy();
99  }
static void destroy()
template<typename TDD>
void folly::UndelayedDestruction< TDD >::onDelayedDestroy ( bool  delayed)
inlineoverride

Definition at line 81 of file UndelayedDestruction.h.

81  {
82  if (delayed && !this->TDD::getDestroyPending()) {
83  return;
84  }
85  // Do nothing. This will always be invoked from the call to destroy
86  // inside our destructor.
87  assert(!delayed);
88  // prevent unused variable warnings when asserts are compiled out.
89  (void)delayed;
90  }
template<typename TDD>
UndelayedDestruction& folly::UndelayedDestruction< TDD >::operator= ( UndelayedDestruction< TDD > const &  )
privatedelete

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