From 54911fba79e5a3e1b2e46ad4b136da43b3bc088f Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 4 Mar 2014 21:48:49 +0000 Subject: Add support for arbitrary functors to CrashRecoveryContext. llvm-svn: 202895 --- llvm/lib/Support/CrashRecoveryContext.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'llvm/lib/Support') 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 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 Fn; CrashRecoveryContext *CRC; bool Result; }; @@ -344,11 +352,12 @@ struct RunSafelyOnThreadInfo { static void RunSafelyOnThread_Dispatch(void *UserData) { RunSafelyOnThreadInfo *Info = reinterpret_cast(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 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(); -- cgit v1.2.3