LLVM 22.0.0git
llvm::CrashRecoveryContextCleanupRegistrar< T, Cleanup > Class Template Reference

Helper class for managing resource cleanups. More...

#include "llvm/Support/CrashRecoveryContext.h"

Public Member Functions

 CrashRecoveryContextCleanupRegistrar (T *x)
 ~CrashRecoveryContextCleanupRegistrar ()
void unregister ()

Detailed Description

template<typename T, typename Cleanup = CrashRecoveryContextDeleteCleanup<T>>
class llvm::CrashRecoveryContextCleanupRegistrar< T, Cleanup >

Helper class for managing resource cleanups.

Template Parameters
TType of resource been reclaimed.
CleanupClass that defines how the resource is reclaimed.

Clients create objects of this type in the code executed in a crash recovery context to ensure that the resource will be reclaimed even in the case of crash. For example:

void actual_work(void *) {
...
std::unique_ptr<Resource> R(new Resource());
...
}
void foo() {
if (!CRC.RunSafely(actual_work, 0)) {
... a crash was detected, report error to user ...
}
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
#define error(X)
Crash recovery helper object.
LLVM_ABI bool RunSafely(function_ref< void()> Fn)
Execute the provided callback function (with the given arguments) in a protected context.

If the code of actual_work in the example above does not crash, the destructor of CrashRecoveryContextCleanupRegistrar removes cleanup code from the current CrashRecoveryContext and the resource is reclaimed by the destructor of std::unique_ptr. If crash happens, destructors are not called and the resource is reclaimed by cleanup object registered in the recovery context by the constructor of CrashRecoveryContextCleanupRegistrar.

Definition at line 257 of file CrashRecoveryContext.h.

Constructor & Destructor Documentation

◆ CrashRecoveryContextCleanupRegistrar()

template<typename T, typename Cleanup = CrashRecoveryContextDeleteCleanup<T>>
llvm::CrashRecoveryContextCleanupRegistrar< T, Cleanup >::CrashRecoveryContextCleanupRegistrar ( T * x)
inline

Definition at line 261 of file CrashRecoveryContext.h.

References Cleanup, and T.

◆ ~CrashRecoveryContextCleanupRegistrar()

template<typename T, typename Cleanup = CrashRecoveryContextDeleteCleanup<T>>
llvm::CrashRecoveryContextCleanupRegistrar< T, Cleanup >::~CrashRecoveryContextCleanupRegistrar ( )
inline

Definition at line 267 of file CrashRecoveryContext.h.

References unregister().

Member Function Documentation

◆ unregister()

template<typename T, typename Cleanup = CrashRecoveryContextDeleteCleanup<T>>
void llvm::CrashRecoveryContextCleanupRegistrar< T, Cleanup >::unregister ( )
inline

Definition at line 269 of file CrashRecoveryContext.h.

Referenced by ~CrashRecoveryContextCleanupRegistrar().


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