diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-03-04 21:48:49 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-03-04 21:48:49 +0000 |
commit | 943d1fdffe805f6e026529a30167acdc324fb667 (patch) | |
tree | 785c816aa3ab7b6d1a907202afbfd712a6adbf53 /lib | |
parent | f0a0ceb0341db6288d6a3c4c1117cf6f36d5528b (diff) | |
download | llvm-943d1fdffe805f6e026529a30167acdc324fb667.tar.gz llvm-943d1fdffe805f6e026529a30167acdc324fb667.tar.bz2 llvm-943d1fdffe805f6e026529a30167acdc324fb667.tar.xz |
Add support for arbitrary functors to CrashRecoveryContext.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202895 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Support/CrashRecoveryContext.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/Support/CrashRecoveryContext.cpp b/lib/Support/CrashRecoveryContext.cpp index 29f73fc539..614980f718 100644 --- a/lib/Support/CrashRecoveryContext.cpp +++ b/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(); |