[llvm-branch-commits] [llvm-branch] r118530 - in /llvm/branches/Apple/whitney: include/llvm/Support/CrashRecoveryContext.h lib/Support/CrashRecoveryContext.cpp

Daniel Dunbar daniel at zuster.org
Tue Nov 9 09:28:24 PST 2010


Author: ddunbar
Date: Tue Nov  9 11:28:24 2010
New Revision: 118530

URL: http://llvm.org/viewvc/llvm-project?rev=118530&view=rev
Log:
Merge r118272:
--
Author: Daniel Dunbar <daniel at zuster.org>
Date:   Fri Nov 5 07:19:09 2010 +0000

    CrashRecoveryContext: Add RunSafelyOnThread helper function.

Modified:
    llvm/branches/Apple/whitney/include/llvm/Support/CrashRecoveryContext.h
    llvm/branches/Apple/whitney/lib/Support/CrashRecoveryContext.cpp

Modified: llvm/branches/Apple/whitney/include/llvm/Support/CrashRecoveryContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/include/llvm/Support/CrashRecoveryContext.h?rev=118530&r1=118529&r2=118530&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/include/llvm/Support/CrashRecoveryContext.h (original)
+++ llvm/branches/Apple/whitney/include/llvm/Support/CrashRecoveryContext.h Tue Nov  9 11:28:24 2010
@@ -67,6 +67,14 @@
   /// the backtrace of the crash on failures.
   bool RunSafely(void (*Fn)(void*), void *UserData);
 
+  /// \brief Execute the provide callback function (with the given arguments) in
+  /// a protected context which is run in another thread (optionally with a
+  /// requested stack size).
+  ///
+  /// See RunSafely() and llvm_execute_on_thread().
+  bool RunSafelyOnThread(void (*Fn)(void*), void *UserData,
+                         unsigned RequestedStackSize = 0);
+
   /// \brief Explicitly trigger a crash recovery in the current process, and
   /// return failure from RunSafely(). This function does not return.
   void HandleCrash();

Modified: llvm/branches/Apple/whitney/lib/Support/CrashRecoveryContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/whitney/lib/Support/CrashRecoveryContext.cpp?rev=118530&r1=118529&r2=118530&view=diff
==============================================================================
--- llvm/branches/Apple/whitney/lib/Support/CrashRecoveryContext.cpp (original)
+++ llvm/branches/Apple/whitney/lib/Support/CrashRecoveryContext.cpp Tue Nov  9 11:28:24 2010
@@ -205,3 +205,26 @@
   assert(CRC->Failed && "No crash was detected!");
   return CRC->Backtrace;
 }
+
+//
+
+namespace {
+struct RunSafelyOnThreadInfo {
+  void (*UserFn)(void*);
+  void *UserData;
+  CrashRecoveryContext *CRC;
+  bool Result;
+};
+}
+
+static void RunSafelyOnThread_Dispatch(void *UserData) {
+  RunSafelyOnThreadInfo *Info =
+    reinterpret_cast<RunSafelyOnThreadInfo*>(UserData);
+  Info->Result = Info->CRC->RunSafely(Info->UserFn, Info->UserData);
+}
+bool CrashRecoveryContext::RunSafelyOnThread(void (*Fn)(void*), void *UserData,
+                                             unsigned RequestedStackSize) {
+  RunSafelyOnThreadInfo Info = { Fn, UserData, this, false };
+  llvm_execute_on_thread(RunSafelyOnThread_Dispatch, &Info, RequestedStackSize);
+  return Info.Result;
+}





More information about the llvm-branch-commits mailing list