summaryrefslogtreecommitdiff
path: root/lib/Support/CrashRecoveryContext.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-03-18 02:05:11 +0000
committerTed Kremenek <kremenek@apple.com>2011-03-18 02:05:11 +0000
commita4f983970133c934d6af66dc8dc50fbf908c31dd (patch)
tree0586d2ad8937ad6dc17c931b8148cdebf689ee7c /lib/Support/CrashRecoveryContext.cpp
parentefdc115c8299a6ddbf164d6bc78ccc873436c224 (diff)
downloadllvm-a4f983970133c934d6af66dc8dc50fbf908c31dd.tar.gz
llvm-a4f983970133c934d6af66dc8dc50fbf908c31dd.tar.bz2
llvm-a4f983970133c934d6af66dc8dc50fbf908c31dd.tar.xz
Augment CrashRecoveryContext to have registered "cleanup" objects that can be used to release resources during a crash.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127849 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/CrashRecoveryContext.cpp')
-rw-r--r--lib/Support/CrashRecoveryContext.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/Support/CrashRecoveryContext.cpp b/lib/Support/CrashRecoveryContext.cpp
index bf8ca3f844..e190051e6d 100644
--- a/lib/Support/CrashRecoveryContext.cpp
+++ b/lib/Support/CrashRecoveryContext.cpp
@@ -57,7 +57,18 @@ public:
static sys::Mutex gCrashRecoveryContexMutex;
static bool gCrashRecoveryEnabled = false;
+CrashRecoveryContextCleanup::~CrashRecoveryContextCleanup() {}
+
CrashRecoveryContext::~CrashRecoveryContext() {
+ // Reclaim registered resources.
+ CrashRecoveryContextCleanup *i = head;
+ while (i) {
+ CrashRecoveryContextCleanup *tmp = i;
+ i = tmp->next;
+ tmp->recoverResources();
+ delete tmp;
+ }
+
CrashRecoveryContextImpl *CRCI = (CrashRecoveryContextImpl *) Impl;
delete CRCI;
}
@@ -70,6 +81,33 @@ CrashRecoveryContext *CrashRecoveryContext::GetCurrent() {
return CRCI->CRC;
}
+void CrashRecoveryContext::registerCleanup(CrashRecoveryContextCleanup *cleanup)
+{
+ if (!cleanup)
+ return;
+ if (head)
+ head->prev = cleanup;
+ cleanup->next = head;
+ head = cleanup;
+}
+
+void
+CrashRecoveryContext::unregisterCleanup(CrashRecoveryContextCleanup *cleanup) {
+ if (!cleanup)
+ return;
+ if (cleanup == head) {
+ head = cleanup->next;
+ if (head)
+ head->prev = 0;
+ }
+ else {
+ cleanup->prev->next = cleanup->next;
+ if (cleanup->next)
+ cleanup->next->prev = cleanup->prev;
+ }
+ delete cleanup;
+}
+
#ifdef LLVM_ON_WIN32
// FIXME: No real Win32 implementation currently.