proxygen
|
#include <DestructorCheck.h>
Classes | |
class | ForwardLink |
class | Safety |
Public Member Functions | |
virtual | ~DestructorCheck () |
Private Attributes | |
ForwardLink | rootGuard_ |
DestructorCheck is a helper class that helps to detect if a tracked object was deleted. This is useful for objects that request callbacks from other components.
Classes needing this functionality should:
Callback context can be extended with an instance of DestructorCheck::Safety object initialized with a reference to the object dereferenced from the callback. Once the callback is invoked, it can use this safety object to check if the object was not deallocated yet before dereferencing it.
DestructorCheck does not perform any locking. It is intended to be used only from a single thread.
Example:
class AsyncFoo : public DestructorCheck { public: ~AsyncFoo(); // awesome async code with circuitous deletion paths void async1(); void async2(); };
righteousFunc(AsyncFoo& f) { DestructorCheck::Safety safety(f);
f.async1(); // might have deleted f, oh noes if (!safety.destroyed()) { // phew, still there f.async2(); } }
Definition at line 57 of file DestructorCheck.h.
|
inlinevirtual |
Definition at line 59 of file DestructorCheck.h.
References rootGuard_, and folly::DestructorCheck::ForwardLink::setAllDestroyed().
|
private |
Definition at line 133 of file DestructorCheck.h.
Referenced by folly::DestructorCheck::Safety::Safety(), and ~DestructorCheck().