summaryrefslogtreecommitdiff
path: root/include/llvm/Support
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2014-03-04 22:13:07 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2014-03-04 22:13:07 +0000
commit6e5887e7e6f5d7aa8bd85074788090de0378dcb0 (patch)
tree2be28a674c0c7f46f7faa66368a5d1005d365f22 /include/llvm/Support
parent943d1fdffe805f6e026529a30167acdc324fb667 (diff)
downloadllvm-6e5887e7e6f5d7aa8bd85074788090de0378dcb0.tar.gz
llvm-6e5887e7e6f5d7aa8bd85074788090de0378dcb0.tar.bz2
llvm-6e5887e7e6f5d7aa8bd85074788090de0378dcb0.tar.xz
Remove dependence on std::function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202902 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support')
-rw-r--r--include/llvm/Support/CrashRecoveryContext.h25
1 files changed, 21 insertions, 4 deletions
diff --git a/include/llvm/Support/CrashRecoveryContext.h b/include/llvm/Support/CrashRecoveryContext.h
index aa5e55eeab..4500efe7b8 100644
--- a/include/llvm/Support/CrashRecoveryContext.h
+++ b/include/llvm/Support/CrashRecoveryContext.h
@@ -10,7 +10,6 @@
#ifndef LLVM_SUPPORT_CRASHRECOVERYCONTEXT_H
#define LLVM_SUPPORT_CRASHRECOVERYCONTEXT_H
-#include <functional>
#include <string>
namespace llvm {
@@ -47,6 +46,17 @@ class CrashRecoveryContext {
void *Impl;
CrashRecoveryContextCleanup *head;
+ /// An adaptor to convert an arbitrary functor into a void(void*), void* pair.
+ template<typename T> struct FunctorAdaptor {
+ T Fn;
+ static void invoke(void *Data) {
+ return static_cast<FunctorAdaptor<T>*>(Data)->Fn();
+ }
+ typedef void Callback(void*);
+ Callback *fn() { return &invoke; }
+ void *arg() { return this; }
+ };
+
public:
CrashRecoveryContext() : Impl(0), head(0) {}
~CrashRecoveryContext();
@@ -76,8 +86,12 @@ public:
/// make as little assumptions as possible about the program state when
/// RunSafely has returned false. Clients can use getBacktrace() to retrieve
/// the backtrace of the crash on failures.
- bool RunSafely(std::function<void()> Fn);
bool RunSafely(void (*Fn)(void*), void *UserData);
+ template<typename Functor>
+ bool RunSafely(Functor Fn) {
+ FunctorAdaptor<Functor> Adaptor = { Fn };
+ return RunSafely(Adaptor.fn(), Adaptor.arg());
+ }
/// \brief Execute the provide callback function (with the given arguments) in
/// a protected context which is run in another thread (optionally with a
@@ -86,8 +100,11 @@ public:
/// See RunSafely() and llvm_execute_on_thread().
bool RunSafelyOnThread(void (*Fn)(void*), void *UserData,
unsigned RequestedStackSize = 0);
- bool RunSafelyOnThread(std::function<void()> Fn,
- unsigned RequestedStackSize = 0);
+ template<typename Functor>
+ bool RunSafelyOnThread(Functor Fn, unsigned RequestedStackSize = 0) {
+ FunctorAdaptor<Functor> Adaptor = { Fn };
+ return RunSafelyOnThread(Adaptor.fn(), Adaptor.arg(), RequestedStackSize);
+ }
/// \brief Explicitly trigger a crash recovery in the current process, and
/// return failure from RunSafely(). This function does not return.