Provide a means for CrashRecovery clients to determine if code is currently running...
authorTed Kremenek <kremenek@apple.com>
Mon, 21 Mar 2011 18:38:03 +0000 (18:38 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 21 Mar 2011 18:38:03 +0000 (18:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128008 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/CrashRecoveryContext.h
lib/Support/CrashRecoveryContext.cpp

index 6e975fe3a1cc6dd9cc56bc15953c71f6ab172d8c..28b31f3a782a62383351dc49795843e88b74c150 100644 (file)
@@ -63,6 +63,10 @@ public:
   /// thread which is in a protected context.
   static CrashRecoveryContext *GetCurrent();
 
+  /// \brief Return true if the current thread is recovering from a
+  /// crash.
+  static bool isRecoveringFromCrash();
+
   /// \brief Execute the provide callback function (with the given arguments) in
   /// a protected context.
   ///
index e558662611f66e17023fd0146746b3aced413b4b..899c3890d78a9940b9f1e2391f375080f70b139c 100644 (file)
@@ -57,11 +57,15 @@ public:
 static sys::Mutex gCrashRecoveryContexMutex;
 static bool gCrashRecoveryEnabled = false;
 
+static sys::ThreadLocal<const CrashRecoveryContextCleanup> 
+       tlIsRecoveringFromCrash;
+
 CrashRecoveryContextCleanup::~CrashRecoveryContextCleanup() {}
 
 CrashRecoveryContext::~CrashRecoveryContext() {
   // Reclaim registered resources.
   CrashRecoveryContextCleanup *i = head;
+  tlIsRecoveringFromCrash.set(head);
   while (i) {
     CrashRecoveryContextCleanup *tmp = i;
     i = tmp->next;
@@ -69,11 +73,16 @@ CrashRecoveryContext::~CrashRecoveryContext() {
     tmp->recoverResources();
     delete tmp;
   }
+  tlIsRecoveringFromCrash.erase();
   
   CrashRecoveryContextImpl *CRCI = (CrashRecoveryContextImpl *) Impl;
   delete CRCI;
 }
 
+bool CrashRecoveryContext::isRecoveringFromCrash() {
+  return tlIsRecoveringFromCrash.get() != 0;
+}
+
 CrashRecoveryContext *CrashRecoveryContext::GetCurrent() {
   if (!gCrashRecoveryEnabled)
     return 0;