proxygen
|
#include <TimeoutQueue.h>
Classes | |
struct | Event |
Public Types | |
typedef int64_t | Id |
typedef std::function< void(Id, int64_t)> | Callback |
Public Member Functions | |
TimeoutQueue () | |
Id | add (int64_t now, int64_t delay, Callback callback) |
Id | addRepeating (int64_t now, int64_t interval, Callback callback) |
bool | erase (Id id) |
int64_t | runOnce (int64_t now) |
int64_t | runLoop (int64_t now) |
int64_t | nextExpiration () const |
Private Types | |
enum | { BY_ID = 0, BY_EXPIRATION = 1 } |
typedef boost::multi_index_container< Event, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::member< Event, Id,&Event::id > >, boost::multi_index::ordered_non_unique< boost::multi_index::member< Event, int64_t,&Event::expiration > > > > | Set |
Private Member Functions | |
int64_t | runInternal (int64_t now, bool runOnce) |
TimeoutQueue (const TimeoutQueue &)=delete | |
TimeoutQueue & | operator= (const TimeoutQueue &)=delete |
Private Attributes | |
Set | timeouts_ |
Id | nextId_ |
Definition at line 40 of file TimeoutQueue.h.
typedef std::function<void(Id, int64_t)> folly::TimeoutQueue::Callback |
Definition at line 43 of file TimeoutQueue.h.
typedef int64_t folly::TimeoutQueue::Id |
Definition at line 42 of file TimeoutQueue.h.
|
private |
Definition at line 119 of file TimeoutQueue.h.
|
private |
Enumerator | |
---|---|
BY_ID | |
BY_EXPIRATION |
Definition at line 121 of file TimeoutQueue.h.
|
inline |
Definition at line 45 of file TimeoutQueue.h.
References add(), addRepeating(), erase(), int64_t, and now().
Referenced by runLoop().
|
privatedelete |
TimeoutQueue::Id folly::TimeoutQueue::add | ( | int64_t | now, |
int64_t | delay, | ||
Callback | callback | ||
) |
Add a one-time timeout event that will fire "delay" time units from "now" (that is, the first time that run*() is called with a time value >= now
Definition at line 24 of file TimeoutQueue.cpp.
References folly::gen::move, nextId_, and timeouts_.
Referenced by TEST(), and TimeoutQueue().
TimeoutQueue::Id folly::TimeoutQueue::addRepeating | ( | int64_t | now, |
int64_t | interval, | ||
Callback | callback | ||
) |
Add a repeating timeout event that will fire every "interval" time units (it will first fire when run*() is called with a time value >= now + interval).
run*() will always invoke each repeating event at most once, even if more than one "interval" period has passed.
Definition at line 31 of file TimeoutQueue.cpp.
References folly::gen::move, nextId_, and timeouts_.
Referenced by TEST(), and TimeoutQueue().
bool folly::TimeoutQueue::erase | ( | Id | id | ) |
Erase a given timeout event, returns true if the event was actually erased and false if it didn't exist in our queue.
Definition at line 43 of file TimeoutQueue.cpp.
References BY_ID, and timeouts_.
Referenced by TEST(), and TimeoutQueue().
int64_t folly::TimeoutQueue::nextExpiration | ( | ) | const |
Return the time that the next event will be due.
Definition at line 37 of file TimeoutQueue.cpp.
References folly::test::begin(), BY_EXPIRATION, max, and timeouts_.
Referenced by runInternal(), and runLoop().
|
privatedelete |
Referenced by runLoop().
Definition at line 47 of file TimeoutQueue.cpp.
References BY_EXPIRATION, folly::test::end(), int64_t, folly::gen::move, nextExpiration(), and timeouts_.
Referenced by runLoop(), and runOnce().
Definition at line 90 of file TimeoutQueue.h.
References int64_t, nextExpiration(), operator=(), runInternal(), runOnce(), and TimeoutQueue().
Referenced by TEST().
Process all events that are due at times <= "now" by calling their callbacks.
Callbacks are allowed to call back into the queue and add / erase events; they might create more events that are already due. In this case, runOnce() will only go through the queue once, and return a "next expiration" time in the past or present (<= now); runLoop() will process the queue again, until there are no events already due.
Note that it is then possible for runLoop to never return if callbacks re-add themselves to the queue (or if you have repeating callbacks with an interval of 0).
Return the time that the next event will be due (same as nextExpiration(), below)
Definition at line 87 of file TimeoutQueue.h.
References runInternal().
Referenced by runLoop(), and TEST().
|
private |
Definition at line 127 of file TimeoutQueue.h.
Referenced by add(), and addRepeating().
|
private |
Definition at line 126 of file TimeoutQueue.h.
Referenced by add(), addRepeating(), erase(), nextExpiration(), and runInternal().