prepare for folly::Executor taking folly::Function
authorSven Over <over@fb.com>
Fri, 12 Aug 2016 09:01:54 +0000 (02:01 -0700)
committerFacebook Github Bot 3 <facebook-github-bot-3-bot@fb.com>
Fri, 12 Aug 2016 09:08:37 +0000 (02:08 -0700)
Summary:
A bunch of small changes that are necessary before we change
the definition of folly::Func from std::function<void()> to
folly::Function<void()>.

Reviewed By: yfeldblum, mzlee

Differential Revision: D3706210

fbshipit-source-id: 198d8a391ef6f545ad4411d316ba9e271ea795e3

folly/futures/ManualExecutor.cpp
folly/futures/ManualExecutor.h
folly/futures/QueuedImmediateExecutor.cpp
folly/futures/test/ViaTest.cpp
folly/io/async/EventBase.h
folly/test/SingletonTest.cpp

index 9b5c87f23944c206219cb8a8cc1a9662bc0f45e3..5586afba7953b53b3a21756650d8d2df29e5515b 100644 (file)
@@ -26,7 +26,7 @@ namespace folly {
 
 void ManualExecutor::add(Func callback) {
   std::lock_guard<std::mutex> lock(lock_);
-  funcs_.push(std::move(callback));
+  funcs_.emplace(std::move(callback));
   sem_.post();
 }
 
@@ -42,7 +42,7 @@ size_t ManualExecutor::run() {
       auto& sf = scheduledFuncs_.top();
       if (sf.time > now_)
         break;
-      funcs_.push(sf.func);
+      funcs_.emplace(sf.moveOutFunc());
       scheduledFuncs_.pop();
     }
 
index 1dfc5bb4fac9da619f4af9ac5bd190433c4f7b8f..db7f012e1f4ba5182da524174027c658fa0bad9f 100644 (file)
@@ -118,7 +118,7 @@ namespace folly {
     struct ScheduledFunc {
       TimePoint time;
       size_t ordinal;
-      Func func;
+      Func mutable func;
 
       ScheduledFunc(TimePoint const& t, Func&& f)
         : time(t), func(std::move(f))
@@ -132,6 +132,10 @@ namespace folly {
           return ordinal < b.ordinal;
         return time < b.time;
       }
+
+      Func&& moveOutFunc() const {
+        return std::move(func);
+      }
     };
     std::priority_queue<ScheduledFunc> scheduledFuncs_;
     TimePoint now_ = now_.min();
index 5a924afda4e3b9b6133fd00a11720ee0fbe07b29..1d2aeea75bb3e0c9517024ff1888dd317742ce38 100644 (file)
@@ -30,7 +30,7 @@ void QueuedImmediateExecutor::addStatic(Func callback) {
       q_->pop();
     }
   } else {
-    q_->push(callback);
+    q_->push(std::move(callback));
   }
 }
 
index 78231873d26213c4cfd438db62687260626c544d..c864b9027c2bd9944fc3090f84856dba2c22214e 100644 (file)
@@ -31,7 +31,7 @@ struct ManualWaiter : public DrivableExecutor {
   explicit ManualWaiter(std::shared_ptr<ManualExecutor> ex) : ex(ex) {}
 
   void add(Func f) override {
-    ex->add(f);
+    ex->add(std::move(f));
   }
 
   void drive() override {
index b450e97fee40762ed82c4ea83cd4797659fc1ee2..6a508129915e08223bfa1b05956a3bf1b2b0205f 100644 (file)
@@ -50,7 +50,7 @@
 
 namespace folly {
 
-typedef std::function<void()> Cob;
+using Cob = Func; // defined in folly/Executor.h
 template <typename MessageT>
 class NotificationQueue;
 
index a5a1cd78fabdcb8eda537ed152dda64d992cb055..42d5bf7d697286aec8d180b70f814f335c04d5c1 100644 (file)
@@ -495,7 +495,7 @@ class TestEagerInitParallelExecutor : public folly::Executor {
 
   virtual void add(folly::Func func) override {
     const auto index = (counter_ ++) % eventBases_.size();
-    eventBases_[index]->add(func);
+    eventBases_[index]->add(std::move(func));
   }
 
  private: