summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-11-05 07:19:09 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-11-05 07:19:09 +0000
commitf4d90ba9f59c6420f6c521df193b8602dc36e7ce (patch)
tree687aa1f3a5b6ec05f51b6512915a0773f9154ce9
parent2a39652303c2c319015d5b97fc569333bbaaa844 (diff)
downloadbcm5719-llvm-f4d90ba9f59c6420f6c521df193b8602dc36e7ce.tar.gz
bcm5719-llvm-f4d90ba9f59c6420f6c521df193b8602dc36e7ce.zip
CrashRecoveryContext: Add RunSafelyOnThread helper function.
llvm-svn: 118272
-rw-r--r--llvm/include/llvm/Support/CrashRecoveryContext.h8
-rw-r--r--llvm/lib/Support/CrashRecoveryContext.cpp23
2 files changed, 31 insertions, 0 deletions
diff --git a/llvm/include/llvm/Support/CrashRecoveryContext.h b/llvm/include/llvm/Support/CrashRecoveryContext.h
index d66609fddfe..2e9b5d4aa54 100644
--- a/llvm/include/llvm/Support/CrashRecoveryContext.h
+++ b/llvm/include/llvm/Support/CrashRecoveryContext.h
@@ -67,6 +67,14 @@ public:
/// 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();
diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp
index 93af79bc0f5..f24d6bdad84 100644
--- a/llvm/lib/Support/CrashRecoveryContext.cpp
+++ b/llvm/lib/Support/CrashRecoveryContext.cpp
@@ -205,3 +205,26 @@ const std::string &CrashRecoveryContext::getBacktrace() const {
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;
+}
OpenPOWER on IntegriCloud