Commit 054b2c1a authored by Eric Niebler's avatar Eric Niebler Committed by Facebook Github Bot

use folly::FunctionRef for EventBase::run(ImmediatelyOrRun)?InEventBaseThreadAndWait

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
parent 219f48ef
...@@ -548,7 +548,7 @@ bool EventBase::runInEventBaseThread(Func fn) { ...@@ -548,7 +548,7 @@ bool EventBase::runInEventBaseThread(Func fn) {
return true; return true;
} }
bool EventBase::runInEventBaseThreadAndWait(Func fn) { bool EventBase::runInEventBaseThreadAndWait(FuncRef fn) {
if (inRunningEventBaseThread()) { if (inRunningEventBaseThread()) {
LOG(ERROR) << "EventBase " << this << ": Waiting in the event loop is not " LOG(ERROR) << "EventBase " << this << ": Waiting in the event loop is not "
<< "allowed"; << "allowed";
...@@ -575,7 +575,7 @@ bool EventBase::runInEventBaseThreadAndWait(Func fn) { ...@@ -575,7 +575,7 @@ bool EventBase::runInEventBaseThreadAndWait(Func fn) {
return true; return true;
} }
bool EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(Func fn) { bool EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(FuncRef fn) {
if (isInEventBaseThread()) { if (isInEventBaseThread()) {
fn(); fn();
return true; return true;
......
...@@ -127,6 +127,7 @@ class EventBase : private boost::noncopyable, ...@@ -127,6 +127,7 @@ class EventBase : private boost::noncopyable,
public DrivableExecutor { public DrivableExecutor {
public: public:
using Func = folly::Function<void()>; using Func = folly::Function<void()>;
using FuncRef = folly::FunctionRef<void()>;
/** /**
* A callback interface to use with runInLoop() * A callback interface to use with runInLoop()
...@@ -416,7 +417,7 @@ class EventBase : private boost::noncopyable, ...@@ -416,7 +417,7 @@ class EventBase : private boost::noncopyable,
* Like runInEventBaseThread, but the caller waits for the callback to be * Like runInEventBaseThread, but the caller waits for the callback to be
* executed. * 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
...@@ -429,7 +430,7 @@ class EventBase : private boost::noncopyable, ...@@ -429,7 +430,7 @@ class EventBase : private boost::noncopyable,
* 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. * 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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment