use folly::FunctionRef for EventBase::run(ImmediatelyOrRun)?InEventBaseThreadAndWait
authorEric Niebler <eniebler@fb.com>
Tue, 20 Dec 2016 22:56:37 +0000 (14:56 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 20 Dec 2016 23:03:02 +0000 (15:03 -0800)
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

folly/io/async/EventBase.cpp
folly/io/async/EventBase.h

index 0f09c69531b2759301d297886722a2fa2f561746..db87e0d873a034ef6d7a896567782b0b6bcc81e2 100644 (file)
@@ -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;
index 9c6f1d7348a9895e3dd6242695ddce06db7d0c33..922effdb983925d0f5e86d15f25f0b8653697a7e 100644 (file)
@@ -127,6 +127,7 @@ class EventBase : private boost::noncopyable,
                   public DrivableExecutor {
  public:
   using Func = folly::Function<void()>;
+  using FuncRef = folly::FunctionRef<void()>;
 
   /**
    * 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