summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/CrashRecoveryContext.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2014-03-04 21:48:49 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2014-03-04 21:48:49 +0000
commit54911fba79e5a3e1b2e46ad4b136da43b3bc088f (patch)
tree1dea6be50e7fb73cdaf6679dded3e5b0047abea5 /llvm/lib/Support/CrashRecoveryContext.cpp
parent5bc79bfc101ab7a0af2e8ff77ab6e70002e9d4c5 (diff)
downloadbcm5719-llvm-54911fba79e5a3e1b2e46ad4b136da43b3bc088f.tar.gz
bcm5719-llvm-54911fba79e5a3e1b2e46ad4b136da43b3bc088f.zip
Add support for arbitrary functors to CrashRecoveryContext.
llvm-svn: 202895
Diffstat (limited to 'llvm/lib/Support/CrashRecoveryContext.cpp')
-rw-r--r--llvm/lib/Support/CrashRecoveryContext.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp
index 29f73fc539c..614980f718a 100644
--- a/llvm/lib/Support/CrashRecoveryContext.cpp
+++ b/llvm/lib/Support/CrashRecoveryContext.cpp
@@ -302,6 +302,10 @@ void CrashRecoveryContext::Disable() {
#endif
bool CrashRecoveryContext::RunSafely(void (*Fn)(void*), void *UserData) {
+ return RunSafely([&]() { Fn(UserData); });
+}
+
+bool CrashRecoveryContext::RunSafely(std::function<void()> Fn) {
// If crash recovery is disabled, do nothing.
if (gCrashRecoveryEnabled) {
assert(!Impl && "Crash recovery context already initialized!");
@@ -313,7 +317,7 @@ bool CrashRecoveryContext::RunSafely(void (*Fn)(void*), void *UserData) {
}
}
- Fn(UserData);
+ Fn();
return true;
}
@@ -332,10 +336,14 @@ const std::string &CrashRecoveryContext::getBacktrace() const {
//
+bool CrashRecoveryContext::RunSafelyOnThread(void (*Fn)(void*), void *UserData,
+ unsigned RequestedStackSize) {
+ return RunSafelyOnThread([&]() { Fn(UserData); }, RequestedStackSize);
+}
+
namespace {
struct RunSafelyOnThreadInfo {
- void (*UserFn)(void*);
- void *UserData;
+ std::function<void()> Fn;
CrashRecoveryContext *CRC;
bool Result;
};
@@ -344,11 +352,12 @@ struct RunSafelyOnThreadInfo {
static void RunSafelyOnThread_Dispatch(void *UserData) {
RunSafelyOnThreadInfo *Info =
reinterpret_cast<RunSafelyOnThreadInfo*>(UserData);
- Info->Result = Info->CRC->RunSafely(Info->UserFn, Info->UserData);
+ Info->Result = Info->CRC->RunSafely(Info->Fn);
}
-bool CrashRecoveryContext::RunSafelyOnThread(void (*Fn)(void*), void *UserData,
+
+bool CrashRecoveryContext::RunSafelyOnThread(std::function<void()> Fn,
unsigned RequestedStackSize) {
- RunSafelyOnThreadInfo Info = { Fn, UserData, this, false };
+ RunSafelyOnThreadInfo Info = { Fn, this, false };
llvm_execute_on_thread(RunSafelyOnThread_Dispatch, &Info, RequestedStackSize);
if (CrashRecoveryContextImpl *CRC = (CrashRecoveryContextImpl *)Impl)
CRC->setSwitchedThread();
OpenPOWER on IntegriCloud