proxygen
|
#include <ManualExecutor.h>
Classes | |
struct | ScheduledFunc |
Public Member Functions | |
~ManualExecutor () | |
void | add (Func) override |
size_t | run () |
size_t | drain () |
void | wait () |
Wait for work to do. More... | |
void | makeProgress () |
Wait for work to do, and do it. More... | |
void | drive () override |
Implements DrivableExecutor. More... | |
template<class F > | |
void | waitFor (F const &f) |
makeProgress until this Future is ready. More... | |
void | scheduleAt (Func &&f, TimePoint const &t) override |
void | advance (Duration const &dur) |
void | advanceTo (TimePoint const &t) |
TimePoint | now () override |
Get this executor's notion of time. Must be threadsafe. More... | |
std::size_t | clear () |
Public Member Functions inherited from folly::DrivableExecutor | |
~DrivableExecutor () override=default | |
Public Member Functions inherited from folly::Executor | |
virtual | ~Executor () |
virtual void | addWithPriority (Func, int8_t priority) |
virtual uint8_t | getNumPriorities () const |
Public Member Functions inherited from folly::ScheduledExecutor | |
~ScheduledExecutor () override=default | |
void | schedule (Func &&a) |
Alias for add() (for Rx consistency) More... | |
void | schedule (Func &&a, Duration const &dur) |
Private Attributes | |
std::mutex | lock_ |
std::queue< Func > | funcs_ |
LifoSem | sem_ |
std::priority_queue< ScheduledFunc > | scheduledFuncs_ |
TimePoint | now_ = TimePoint::min() |
Additional Inherited Members | |
Public Types inherited from folly::ScheduledExecutor | |
typedef std::chrono::microseconds | Duration |
typedef std::chrono::steady_clock::time_point | TimePoint |
Static Public Member Functions inherited from folly::Executor | |
template<typename ExecutorT > | |
static KeepAlive< ExecutorT > | getKeepAliveToken (ExecutorT *executor) |
template<typename ExecutorT > | |
static KeepAlive< ExecutorT > | getKeepAliveToken (ExecutorT &executor) |
Static Public Attributes inherited from folly::Executor | |
static const int8_t | LO_PRI = SCHAR_MIN |
static const int8_t | MID_PRI = 0 |
static const int8_t | HI_PRI = SCHAR_MAX |
Protected Member Functions inherited from folly::Executor | |
virtual bool | keepAliveAcquire () |
virtual void | keepAliveRelease () |
Static Protected Member Functions inherited from folly::Executor | |
template<typename ExecutorT > | |
static bool | isKeepAliveDummy (const KeepAlive< ExecutorT > &keepAlive) |
template<typename ExecutorT > | |
static KeepAlive< ExecutorT > | makeKeepAlive (ExecutorT *executor) |
A ManualExecutor only does work when you turn the crank, by calling run() or indirectly with makeProgress() or waitFor().
The clock for a manual executor starts at 0 and advances only when you ask it to. i.e. time is also under manual control.
NB No attempt has been made to make anything other than add and schedule threadsafe.
Definition at line 38 of file ManualExecutor.h.
folly::ManualExecutor::~ManualExecutor | ( | ) |
Definition at line 25 of file ManualExecutor.cpp.
References drain().
|
overridevirtual |
Enqueue a function to executed by this executor. This and all variants must be threadsafe.
Implements folly::ScheduledExecutor.
Definition at line 29 of file ManualExecutor.cpp.
References funcs_, folly::lock(), lock_, folly::gen::move, folly::detail::LifoSemBase< Handoff, Atom >::post(), and sem_.
Referenced by TEST().
|
inline |
Advance the clock. The clock never advances on its own. Advancing the clock causes some work to be done, if work is available to do (perhaps newly available because of the advanced clock). If dur is <= 0 this is a noop.
Definition at line 100 of file ManualExecutor.h.
References advanceTo(), now_, and folly::pushmi::detail::t.
Referenced by TEST().
void folly::ManualExecutor::advanceTo | ( | TimePoint const & | t | ) |
Advance the clock to this absolute time. If t is <= now(), this is a noop.
Definition at line 98 of file ManualExecutor.cpp.
References now_, run(), and folly::pushmi::detail::t.
Referenced by advance(), and TEST().
|
inline |
Flush the function queue. Destroys all stored functions without executing them. Returns number of removed functions.
Definition at line 114 of file ManualExecutor.h.
References funcs_, folly::lock(), lock_, and scheduledFuncs_.
Referenced by TEST().
size_t folly::ManualExecutor::drain | ( | ) |
Definition at line 76 of file ManualExecutor.cpp.
References run().
Referenced by TEST(), and ~ManualExecutor().
|
inlineoverridevirtual |
Implements DrivableExecutor.
Implements folly::DrivableExecutor.
Definition at line 72 of file ManualExecutor.h.
References makeProgress().
|
inline |
Wait for work to do, and do it.
Definition at line 66 of file ManualExecutor.h.
Referenced by drive(), and waitFor().
|
inlineoverridevirtual |
Get this executor's notion of time. Must be threadsafe.
Reimplemented from folly::ScheduledExecutor.
Definition at line 108 of file ManualExecutor.h.
References now_.
Referenced by TEST().
size_t folly::ManualExecutor::run | ( | ) |
Do work. Returns the number of functions that were executed (maybe 0). Non-blocking, in the sense that we don't wait for work (we can't control whether one of the functions blocks). This is stable, it will not chase an ever-increasing tail of work. This also means, there may be more work available to perform at the moment that this returns.
Definition at line 35 of file ManualExecutor.cpp.
References count, funcs_, folly::lock(), lock_, folly::gen::move, now_, scheduledFuncs_, sem_, and folly::detail::LifoSemBase< Handoff, Atom >::tryWait().
Referenced by advanceTo(), drain(), makeProgress(), TEST(), and waitFor().
Schedule a Func to be executed at time t, or as soon afterward as possible. Expect millisecond resolution at best. Must be threadsafe.
Reimplemented from folly::ScheduledExecutor.
Definition at line 90 of file ManualExecutor.h.
References f, folly::lock(), lock_, folly::gen::move, folly::detail::LifoSemBase< Handoff, Atom >::post(), scheduledFuncs_, and sem_.
Referenced by TEST().
void folly::ManualExecutor::wait | ( | ) |
Wait for work to do.
Definition at line 85 of file ManualExecutor.cpp.
References funcs_, folly::lock(), lock_, sem_, and folly::detail::LifoSemBase< Handoff, Atom >::wait().
Referenced by makeProgress().
|
inline |
makeProgress until this Future is ready.
Definition at line 78 of file ManualExecutor.h.
References makeProgress(), and run().
Referenced by TEST().
|
private |
|
private |
Definition at line 128 of file ManualExecutor.h.
Referenced by add(), clear(), run(), scheduleAt(), and wait().
|
private |
Definition at line 158 of file ManualExecutor.h.
Referenced by advance(), advanceTo(), now(), and run().
|
private |
Definition at line 157 of file ManualExecutor.h.
Referenced by clear(), run(), and scheduleAt().
|
private |
Definition at line 130 of file ManualExecutor.h.
Referenced by add(), run(), scheduleAt(), and wait().