10 #ifndef LLVM_SUPPORT_CRASHRECOVERYCONTEXT_H 11 #define LLVM_SUPPORT_CRASHRECOVERYCONTEXT_H 16 class CrashRecoveryContextCleanup;
84 return RunSafely([&]() { Fn(UserData); });
97 unsigned RequestedStackSize = 0) {
117 : context(context), cleanupFired(
false) {}
123 virtual void recoverResources() = 0;
145 template<
typename Derived,
typename T>
160 return new Derived(context, x);
167 template <
typename T>
177 this->resource->~T();
182 template <
typename T>
194 template <
typename T>
201 T>(context, resource) {}
237 template <
typename T,
typename Cleanup = CrashRecoveryContextDeleteCleanup<T> >
243 : cleanup(Cleanup::create(x)) {
258 #endif // LLVM_SUPPORT_CRASHRECOVERYCONTEXT_H static Derived * create(T *x)
Creates cleanup handler.
This class represents lattice values for constants.
Cleanup handler that reclaims resource by calling destructor on it.
Helper class for managing resource cleanups.
Cleanup handler that reclaims resource by calling its method 'Release'.
An efficient, type-erasing, non-owning reference to a callable.
static CrashRecoveryContext * GetCurrent()
Return the active context, if the code is currently executing in a thread which is in a protected con...
void recoverResources() override
static void cleanup(BlockFrequencyInfoImplBase &BFI)
Clear all memory not needed downstream.
void recoverResources() override
~CrashRecoveryContextCleanupRegistrar()
virtual void recoverResources()
void HandleCrash()
Explicitly trigger a crash recovery in the current process, and return failure from RunSafely()...
CrashRecoveryContextDeleteCleanup(CrashRecoveryContext *context, T *resource)
void unregisterCleanup(CrashRecoveryContextCleanup *cleanup)
Base class of cleanup handler that controls recovery of resources of the given type.
static void Enable()
Enable crash recovery.
Abstract base class of cleanup handlers.
CrashRecoveryContextCleanup(CrashRecoveryContext *context)
bool RunSafelyOnThread(function_ref< void()>, unsigned RequestedStackSize=0)
Execute the provide callback function (with the given arguments) in a protected context which is run ...
bool RunSafelyOnThread(void(*Fn)(void *), void *UserData, unsigned RequestedStackSize=0)
void registerCleanup(CrashRecoveryContextCleanup *cleanup)
Register cleanup handler, which is used when the recovery context is finished.
bool RunSafely(void(*Fn)(void *), void *UserData)
CrashRecoveryContextReleaseRefCleanup(CrashRecoveryContext *context, T *resource)
CrashRecoveryContext * context
bool RunSafely(function_ref< void()> Fn)
Execute the provided callback function (with the given arguments) in a protected context.
Crash recovery helper object.
Cleanup handler that reclaims resource by calling 'delete' on it.
CrashRecoveryContext * getContext() const
CrashRecoveryContextCleanupBase(CrashRecoveryContext *context, T *resource)
static bool isRecoveringFromCrash()
Return true if the current thread is recovering from a crash.
CrashRecoveryContextCleanupRegistrar(T *x)
static void Disable()
Disable crash recovery.
CrashRecoveryContextDestructorCleanup(CrashRecoveryContext *context, T *resource)