RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
Public Types | |
typedef std::function< void(volatile int &shutdown_, int64_t threadId)> | SubordinateThreadFn |
Public Member Functions | |
MessageLoop (int numThreads=1, double maxAddedLatency=0.0005) | |
void | init (int numThreads=1, double maxAddedLatency=0.0005) |
void | start (std::function< void()> onStop=std::function< void()>()) |
void | startSync () |
void | shutdown () |
void | addSource (const std::string &name, AsyncEventSource &source, int priority=0) |
void | addSource (const std::string &name, std::shared_ptr< AsyncEventSource > source, int priority=0) |
void | addPeriodic (const std::string &name, double timePeriodSeconds, std::function< void(uint64_t)> toRun, int priority=0) |
void | addSourceDeferred (const std::string &name, AsyncEventSource &source, int priority=0) |
void | addSourceDeferred (const std::string &name, std::shared_ptr< AsyncEventSource > source, int priority=0) |
void | addPeriodicDeferred (const std::string &name, double timePeriodSeconds, std::function< void(uint64_t)> toRun, int priority=0) |
void | startSubordinateThread (const SubordinateThreadFn &mainFn) |
virtual bool | processOne () |
virtual bool | poll () const |
void | debug (bool debugOn) |
void | removeSource (AsyncEventSource *source) |
void | checkNeedsPoll () |
double | totalSleepSeconds () const |
Definition at line 28 of file message_loop.h.
void Datacratic::MessageLoop::addPeriodic | ( | const std::string & | name, |
double | timePeriodSeconds, | ||
std::function< void(uint64_t)> | toRun, | ||
int | priority = 0 |
||
) |
Add a periodic job to be performed by the loop. The number passed to the toRun function is the number of timeouts that have elapsed since the last call; this is useful to know if something has got behind. It will normally be 1.
This method cannot be called from within an event processed by the message loop (that would deadlock); instead use addPeriodicDeferred().
Definition at line 136 of file message_loop.cc.
void Datacratic::MessageLoop::addPeriodicDeferred | ( | const std::string & | name, |
double | timePeriodSeconds, | ||
std::function< void(uint64_t)> | toRun, | ||
int | priority = 0 |
||
) |
Add a periodic job to be performed by the loop. The number passed to the toRun function is the number of timeouts that have elapsed since the last call; this is useful to know if something has got behind. It will normally be 1.
This method can only be called from within an event processed by the message loop; the handler will actually be added after the next event finishes processing.
Definition at line 169 of file message_loop.cc.
void Datacratic::MessageLoop::addSource | ( | const std::string & | name, |
AsyncEventSource & | source, | ||
int | priority = 0 |
||
) |
Add the given source of asynchronous wakeups with the given callback to be run when they trigger.
This method cannot be called from within an event processed by the message loop (that would deadlock); instead use addPeriodicDeferred().
Definition at line 119 of file message_loop.cc.
void Datacratic::MessageLoop::addSource | ( | const std::string & | name, |
std::shared_ptr< AsyncEventSource > | source, | ||
int | priority = 0 |
||
) |
Add the given source of asynchronous wakeups with the given callback to be run when they trigger.
This method cannot be called from within an event processed by the message loop (that would deadlock); instead use addPeriodicDeferred().
Definition at line 127 of file message_loop.cc.
void Datacratic::MessageLoop::addSourceDeferred | ( | const std::string & | name, |
AsyncEventSource & | source, | ||
int | priority = 0 |
||
) |
Add the given source of asynchronous wakeups with the given callback to be run when they trigger.
This method can only be called from within an event processed by the message loop; the handler will actually be added after the next event finishes processing.
Definition at line 149 of file message_loop.cc.
void Datacratic::MessageLoop::addSourceDeferred | ( | const std::string & | name, |
std::shared_ptr< AsyncEventSource > | source, | ||
int | priority = 0 |
||
) |
Add the given source of asynchronous wakeups with the given callback to be run when they trigger.
This method can only be called from within an event processed by the message loop; the handler will actually be added after the next event finishes processing.
Definition at line 159 of file message_loop.cc.
Re-check if anything needs to poll.
Definition at line 426 of file message_loop.cc.
void Datacratic::MessageLoop::debug | ( | bool | debugOn | ) | [virtual] |
Sets whether or not it is in debug mode.
Reimplemented from Datacratic::AsyncEventSource.
Definition at line 415 of file message_loop.cc.
bool Datacratic::MessageLoop::poll | ( | ) | const [virtual] |
Returns true if there is work to be done. May be called from more than one thread. Should never block.
Reimplemented from Datacratic::Epoller.
Definition at line 313 of file message_loop.cc.
bool Datacratic::MessageLoop::processOne | ( | ) | [virtual] |
Process a single message and return true if there are more to be processed.
This may be called from more than one thread if singleThreaded() is false.
Reimplemented from Datacratic::Epoller.
Definition at line 327 of file message_loop.cc.
void Datacratic::MessageLoop::removeSource | ( | AsyncEventSource * | source | ) |
Remove the given source from the list of active sources.
Definition at line 182 of file message_loop.cc.
void Datacratic::MessageLoop::startSubordinateThread | ( | const SubordinateThreadFn & | mainFn | ) |
Start a subordinate thread that runs the given function, returning when the passed parameter is non-zero, and manage its lifecycle with this thread.
Definition at line 222 of file message_loop.cc.
double Datacratic::MessageLoop::totalSleepSeconds | ( | ) | const [inline] |
Total number of seconds that this message loop has spent sleeping. Can be polled regularly to determine the duty cycle of the loop.
Definition at line 136 of file message_loop.h.