LLVM 20.0.0git
Public Member Functions | List of all members
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)
Helper class for managing resource cleanups.
Crash recovery helper object.
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 252 of file CrashRecoveryContext.h.

Constructor & Destructor Documentation

◆ CrashRecoveryContextCleanupRegistrar()

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

◆ ~CrashRecoveryContextCleanupRegistrar()

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

Member Function Documentation

◆ unregister()

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

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