return true;
}
-bool EventBase::runInEventBaseThreadAndWait(FuncRef fn) {
+bool EventBase::runInEventBaseThreadAndWait(Func fn) {
if (inRunningEventBaseThread()) {
LOG(ERROR) << "EventBase " << this << ": Waiting in the event loop is not "
<< "allowed";
}
Baton<> ready;
- runInEventBaseThread([&] {
+ runInEventBaseThread([&ready, fn = std::move(fn)]() mutable {
SCOPE_EXIT {
ready.post();
};
- fn();
+ // A trick to force the stored functor to be executed and then destructed
+ // before posting the baton and waking the waiting thread.
+ copy(std::move(fn))();
});
ready.wait();
return true;
}
-bool EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(FuncRef fn) {
+bool EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(Func fn) {
if (isInEventBaseThread()) {
fn();
return true;
public DrivableExecutor {
public:
using Func = folly::Function<void()>;
- using FuncRef = folly::FunctionRef<void()>;
/**
* A callback interface to use with runInLoop()
* Like runInEventBaseThread, but the caller waits for the callback to be
* executed.
*/
- bool runInEventBaseThreadAndWait(FuncRef fn);
+ bool runInEventBaseThreadAndWait(Func fn);
/*
* Like runInEventBaseThreadAndWait, except if the caller is already in the
* Like runInEventBaseThreadAndWait, except if the caller is already in the
* event base thread, the functor is simply run inline.
*/
- bool runImmediatelyOrRunInEventBaseThreadAndWait(FuncRef fn);
+ bool runImmediatelyOrRunInEventBaseThreadAndWait(Func fn);
/**
* Set the maximum desired latency in us and provide a callback which will be