From: Eric Niebler Date: Tue, 20 Dec 2016 22:56:37 +0000 (-0800) Subject: use folly::FunctionRef for EventBase::run(ImmediatelyOrRun)?InEventBaseThreadAndWait X-Git-Tag: v2017.03.06.00~176 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=054b2c1a15f740d59b34273030a582ec26c93794;p=folly.git 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 --- diff --git a/folly/io/async/EventBase.cpp b/folly/io/async/EventBase.cpp index 0f09c695..db87e0d8 100644 --- a/folly/io/async/EventBase.cpp +++ b/folly/io/async/EventBase.cpp @@ -548,7 +548,7 @@ bool EventBase::runInEventBaseThread(Func fn) { return true; } -bool EventBase::runInEventBaseThreadAndWait(Func fn) { +bool EventBase::runInEventBaseThreadAndWait(FuncRef fn) { if (inRunningEventBaseThread()) { LOG(ERROR) << "EventBase " << this << ": Waiting in the event loop is not " << "allowed"; @@ -575,7 +575,7 @@ bool EventBase::runInEventBaseThreadAndWait(Func fn) { return true; } -bool EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(Func fn) { +bool EventBase::runImmediatelyOrRunInEventBaseThreadAndWait(FuncRef fn) { if (isInEventBaseThread()) { fn(); return true; diff --git a/folly/io/async/EventBase.h b/folly/io/async/EventBase.h index 9c6f1d73..922effdb 100644 --- a/folly/io/async/EventBase.h +++ b/folly/io/async/EventBase.h @@ -127,6 +127,7 @@ class EventBase : private boost::noncopyable, public DrivableExecutor { public: using Func = folly::Function; + using FuncRef = folly::FunctionRef; /** * A callback interface to use with runInLoop() @@ -416,7 +417,7 @@ class EventBase : private boost::noncopyable, * 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 @@ -429,7 +430,7 @@ class EventBase : private boost::noncopyable, * 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