[llvm-commits] [llvm] r128008 - in /llvm/trunk: include/llvm/Support/CrashRecoveryContext.h lib/Support/CrashRecoveryContext.cpp

Ted Kremenek kremenek at apple.com
Mon Mar 21 11:38:03 PDT 2011


Author: kremenek
Date: Mon Mar 21 13:38:03 2011
New Revision: 128008

URL: http://llvm.org/viewvc/llvm-project?rev=128008&view=rev
Log:
Provide a means for CrashRecovery clients to determine if code is currently running while crash recovery cleanups are being processed.

Modified:
    llvm/trunk/include/llvm/Support/CrashRecoveryContext.h
    llvm/trunk/lib/Support/CrashRecoveryContext.cpp

Modified: llvm/trunk/include/llvm/Support/CrashRecoveryContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CrashRecoveryContext.h?rev=128008&r1=128007&r2=128008&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/CrashRecoveryContext.h (original)
+++ llvm/trunk/include/llvm/Support/CrashRecoveryContext.h Mon Mar 21 13:38:03 2011
@@ -63,6 +63,10 @@
   /// 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.
   ///

Modified: llvm/trunk/lib/Support/CrashRecoveryContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CrashRecoveryContext.cpp?rev=128008&r1=128007&r2=128008&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CrashRecoveryContext.cpp (original)
+++ llvm/trunk/lib/Support/CrashRecoveryContext.cpp Mon Mar 21 13:38:03 2011
@@ -57,11 +57,15 @@
 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 @@
     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;





More information about the llvm-commits mailing list