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
void ManualExecutor::add(Func callback) {
std::lock_guard<std::mutex> lock(lock_);
- funcs_.push(std::move(callback));
+ funcs_.emplace(std::move(callback));
sem_.post();
}
auto& sf = scheduledFuncs_.top();
if (sf.time > now_)
break;
- funcs_.push(sf.func);
+ funcs_.emplace(sf.moveOutFunc());
scheduledFuncs_.pop();
}
struct ScheduledFunc {
TimePoint time;
size_t ordinal;
- Func func;
+ Func mutable func;
ScheduledFunc(TimePoint const& t, Func&& f)
: time(t), func(std::move(f))
return ordinal < b.ordinal;
return time < b.time;
}
+
+ Func&& moveOutFunc() const {
+ return std::move(func);
+ }
};
std::priority_queue<ScheduledFunc> scheduledFuncs_;
TimePoint now_ = now_.min();
q_->pop();
}
} else {
- q_->push(callback);
+ q_->push(std::move(callback));
}
}
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 {
namespace folly {
-typedef std::function<void()> Cob;
+using Cob = Func; // defined in folly/Executor.h
template <typename MessageT>
class NotificationQueue;
virtual void add(folly::Func func) override {
const auto index = (counter_ ++) % eventBases_.size();
- eventBases_[index]->add(func);
+ eventBases_[index]->add(std::move(func));
}
private: