LLVM  8.0.0svn
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() {
CrashRecoveryContext CRC;
if (!CRC.RunSafely(actual_work, 0)) {
... a crash was detected, report error to user ...
}

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 238 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

Definition at line 248 of file CrashRecoveryContext.h.

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: