Summary: folly::FunctionRef never allocates memory and is cheaper to pass around. Use it in the interface of EventBase where we can.
Reviewed By: yfeldblum
Differential Revision:
D4353992
fbshipit-source-id:
259c5214ed48d30981eb8e38b062aad31d80a080
-bool EventBase::runInEventBaseThreadAndWait(Func fn) {
+bool EventBase::runInEventBaseThreadAndWait(FuncRef fn) {
if (inRunningEventBaseThread()) {
LOG(ERROR) << "EventBase " << this << ": Waiting in the event loop is not "
<< "allowed";
if (inRunningEventBaseThread()) {
LOG(ERROR) << "EventBase " << this << ": Waiting in the event loop is not "
<< "allowed";
-bool EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(Func fn) {
+bool EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(FuncRef fn) {
if (isInEventBaseThread()) {
fn();
return true;
if (isInEventBaseThread()) {
fn();
return true;
public DrivableExecutor {
public:
using Func = folly::Function<void()>;
public DrivableExecutor {
public:
using Func = folly::Function<void()>;
+ using FuncRef = folly::FunctionRef<void()>;
/**
* A callback interface to use with runInLoop()
/**
* A callback interface to use with runInLoop()
* Like runInEventBaseThread, but the caller waits for the callback to be
* executed.
*/
* Like runInEventBaseThread, but the caller waits for the callback to be
* executed.
*/
- bool runInEventBaseThreadAndWait(Func fn);
+ bool runInEventBaseThreadAndWait(FuncRef fn);
/*
* Like runInEventBaseThreadAndWait, except if the caller is already in the
/*
* 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.
*/
* Like runInEventBaseThreadAndWait, except if the caller is already in the
* event base thread, the functor is simply run inline.
*/
- bool runImmediatelyOrRunInEventBaseThreadAndWait(Func fn);
+ bool runImmediatelyOrRunInEventBaseThreadAndWait(FuncRef fn);
/**
* Set the maximum desired latency in us and provide a callback which will be
/**
* Set the maximum desired latency in us and provide a callback which will be