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

Daniel Dunbar daniel at zuster.org
Tue Aug 17 15:32:37 PDT 2010


Author: ddunbar
Date: Tue Aug 17 17:32:37 2010
New Revision: 111308

URL: http://llvm.org/viewvc/llvm-project?rev=111308&view=rev
Log:
CrashRecovery: Add CrashRecoveryContext::GetCurrent(), so clients can find the active context from anywhere.

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=111308&r1=111307&r2=111308&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/CrashRecoveryContext.h (original)
+++ llvm/trunk/include/llvm/Support/CrashRecoveryContext.h Tue Aug 17 17:32:37 2010
@@ -53,6 +53,10 @@
   /// \brief Disable crash recovery.
   static void Disable();
 
+  /// \brief Return the active context, if the code is currently executing in a
+  /// thread which is in a protected context.
+  static CrashRecoveryContext *GetCurrent();
+
   /// \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=111308&r1=111307&r2=111308&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CrashRecoveryContext.cpp (original)
+++ llvm/trunk/lib/Support/CrashRecoveryContext.cpp Tue Aug 17 17:32:37 2010
@@ -23,12 +23,14 @@
 static sys::ThreadLocal<const CrashRecoveryContextImpl> CurrentContext;
 
 struct CrashRecoveryContextImpl {
+  CrashRecoveryContext *CRC;
   std::string Backtrace;
   ::jmp_buf JumpBuffer;
   volatile unsigned Failed : 1;
 
 public:
-  CrashRecoveryContextImpl() : Failed(false) {
+  CrashRecoveryContextImpl(CrashRecoveryContext *CRC) : CRC(CRC),
+                                                        Failed(false) {
     CurrentContext.set(this);
   }
   ~CrashRecoveryContextImpl() {
@@ -56,6 +58,14 @@
   delete CRCI;
 }
 
+CrashRecoveryContext *CrashRecoveryContext::GetCurrent() {
+  const CrashRecoveryContextImpl *CRCI = CurrentContext.get();
+  if (!CRCI)
+    return 0;
+
+  return CRCI->CRC;
+}
+
 #ifdef LLVM_ON_WIN32
 
 // FIXME: No real Win32 implementation currently.
@@ -164,7 +174,7 @@
   // If crash recovery is disabled, do nothing.
   if (gCrashRecoveryEnabled) {
     assert(!Impl && "Crash recovery context already initialized!");
-    CrashRecoveryContextImpl *CRCI = new CrashRecoveryContextImpl;
+    CrashRecoveryContextImpl *CRCI = new CrashRecoveryContextImpl(this);
     Impl = CRCI;
 
     if (setjmp(CRCI->JumpBuffer) != 0) {





More information about the llvm-commits mailing list