Skip to content

Commit

Permalink
Tweak CrashRecoveryContextCleanup to provide an easy method for clien…
Browse files Browse the repository at this point in the history
…ts to select between 'delete' and 'destructor' cleanups, and allow the destructor of CrashRecoveryContextCleanupRegister to be pseudo re-entrant.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127929 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tkremenek committed Mar 19, 2011
1 parent fb200e3 commit 1a06d57
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
28 changes: 22 additions & 6 deletions include/llvm/Support/CrashRecoveryContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,16 @@ class CrashRecoveryContext {

class CrashRecoveryContextCleanup {
public:
bool cleanupFired;
enum ProvidedCleanups { DeleteCleanup, DestructorCleanup };

CrashRecoveryContextCleanup() : cleanupFired(false) {}
virtual ~CrashRecoveryContextCleanup();
virtual void recoverResources() = 0;

template <typename T> static CrashRecoveryContextCleanup *create(T *);
template <typename T> static CrashRecoveryContextCleanup *create(T *,
ProvidedCleanups cleanupKind =
CrashRecoveryContextCleanup::DeleteCleanup);

private:
friend class CrashRecoveryContext;
Expand Down Expand Up @@ -131,15 +137,25 @@ class CrashRecoveryContextDeleteCleanup

template <typename T>
struct CrashRecoveryContextTrait {
static inline CrashRecoveryContextCleanup *createCleanup(T *resource) {
return new CrashRecoveryContextDeleteCleanup<T>(resource);
static inline CrashRecoveryContextCleanup *
createCleanup(T *resource,
CrashRecoveryContextCleanup::ProvidedCleanups cleanup) {
switch (cleanup) {
case CrashRecoveryContextCleanup::DeleteCleanup:
return new CrashRecoveryContextDeleteCleanup<T>(resource);
case CrashRecoveryContextCleanup::DestructorCleanup:
return new CrashRecoveryContextDestructorCleanup<T>(resource);
}
return 0;
}
};

template<typename T>
inline CrashRecoveryContextCleanup* CrashRecoveryContextCleanup::create(T *x) {
inline CrashRecoveryContextCleanup*
CrashRecoveryContextCleanup::create(T *x,
CrashRecoveryContextCleanup::ProvidedCleanups cleanupKind) {
return CrashRecoveryContext::GetCurrent() ?
CrashRecoveryContextTrait<T>::createCleanup(x) :
CrashRecoveryContextTrait<T>::createCleanup(x, cleanupKind) :
0;
}

Expand All @@ -155,7 +171,7 @@ class CrashRecoveryContextCleanupRegistrar {
context->registerCleanup(cleanup);
}
~CrashRecoveryContextCleanupRegistrar() {
if (cleanup) {
if (cleanup && !cleanup->cleanupFired) {
if (context)
context->unregisterCleanup(cleanup);
else
Expand Down
1 change: 1 addition & 0 deletions lib/Support/CrashRecoveryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ CrashRecoveryContext::~CrashRecoveryContext() {
while (i) {
CrashRecoveryContextCleanup *tmp = i;
i = tmp->next;
tmp->cleanupFired = true;
tmp->recoverResources();
delete tmp;
}
Expand Down

0 comments on commit 1a06d57

Please sign in to comment.