Commit 4bbd587c authored by Giuseppe Ottaviano's avatar Giuseppe Ottaviano Committed by Facebook GitHub Bot

Outline most of TimedDrivableExecutor implementation

Summary: This header is widely included (via `Future.h`) and instantiations of `UnboundedQueue`'s methods are expensive, so outline them (note that the template methods will only be instantiated if used, so that's fine).

Reviewed By: philippv

Differential Revision: D22014083

fbshipit-source-id: b6a71c38c142917e9e0d86fbb64a88462382952a
parent 8ae59d46
......@@ -23,6 +23,14 @@
namespace folly {
TimedDrivableExecutor::TimedDrivableExecutor() = default;
TimedDrivableExecutor::~TimedDrivableExecutor() noexcept {
// Drain on destruction so that if work is added here during the collapse
// of a future train, it will propagate.
drain();
}
void TimedDrivableExecutor::add(Func callback) {
queue_.enqueue(std::move(callback));
}
......@@ -32,6 +40,10 @@ void TimedDrivableExecutor::drive() noexcept {
run();
}
bool TimedDrivableExecutor::try_drive() noexcept {
return try_wait() && run() > 0;
}
size_t TimedDrivableExecutor::run() noexcept {
size_t count = 0;
size_t n = queue_.size();
......@@ -67,4 +79,8 @@ void TimedDrivableExecutor::wait() noexcept {
}
}
bool TimedDrivableExecutor::try_wait() noexcept {
return func_ || queue_.try_dequeue(func_);
}
} // namespace folly
......@@ -29,20 +29,15 @@ namespace folly {
*/
class TimedDrivableExecutor : public DrivableExecutor {
public:
~TimedDrivableExecutor() noexcept {
// Drain on destruction so that if work is added here during the collapse
// of a future train, it will propagate.
drain();
}
TimedDrivableExecutor();
~TimedDrivableExecutor() noexcept override;
/// Implements DrivableExecutor
void drive() noexcept override;
// Make progress if there is work to do and return true. Otherwise return
// false.
bool try_drive() noexcept {
return try_wait() && run() > 0;
}
bool try_drive() noexcept;
// Make progress on this Executor's work. Acts as drive, except it will only
// wait for a period of timeout for work to be enqueued. If no work is
......@@ -84,9 +79,7 @@ class TimedDrivableExecutor : public DrivableExecutor {
void wait() noexcept;
// Return true if there is work to do, false otherwise
bool try_wait() noexcept {
return func_ || queue_.try_dequeue(func_);
}
bool try_wait() noexcept;
/// Wait for work to do or for a period of timeout, whichever is sooner.
template <typename Rep, typename Period>
......
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