Commit 4cf30a14 authored by Sven Over's avatar Sven Over Committed by Facebook Github Bot 3

prepare for folly::Executor taking folly::Function

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
parent c44bb620
......@@ -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();
}
......
......@@ -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();
......
......@@ -30,7 +30,7 @@ void QueuedImmediateExecutor::addStatic(Func callback) {
q_->pop();
}
} else {
q_->push(callback);
q_->push(std::move(callback));
}
}
......
......@@ -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 {
......
......@@ -50,7 +50,7 @@
namespace folly {
typedef std::function<void()> Cob;
using Cob = Func; // defined in folly/Executor.h
template <typename MessageT>
class NotificationQueue;
......
......@@ -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:
......
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