LogCabin
|
A Timer is called by the Event::Loop when time has elapsed. More...
#include <Timer.h>
Classes | |
class | Monitor |
Registers a Timer handler to be monitored by the Event::Loop. More... | |
Public Member Functions | |
Timer () | |
Construct a timer but do not schedule it to trigger. | |
virtual | ~Timer () |
Destructor. | |
virtual void | handleTimerEvent ()=0 |
This method is overridden by a subclass and invoked when the timer expires. | |
void | schedule (uint64_t nanoseconds) |
Start the timer. | |
void | scheduleAbsolute (Core::Time::SteadyClock::time_point timeout) |
Start the timer for an absolute point in time. | |
void | deschedule () |
Stop the timer from calling handleTimerEvent(). | |
Private Member Functions | |
bool | isScheduled () const |
Returns true if the timer has been scheduled and has not yet fired. | |
void | handleFileEvent (uint32_t events) |
Generic event handler for files. | |
Timer (const Timer &) | |
Timer & | operator= (const Timer &) |
A Timer is called by the Event::Loop when time has elapsed.
The client should inherit from this and implement the trigger method for when the timer expires.
Timers can be added and scheduled from any thread, but they will always fire on the thread running the Event::Loop.
Construct a timer but do not schedule it to trigger.
After this is constructed, you'll want to create an Event::Timer::Monitor for it and also schedule() it, in either order.
LogCabin::Event::Timer::~Timer | ( | ) | [virtual] |
LogCabin::Event::Timer::Timer | ( | const Timer & | ) | [private] |
virtual void LogCabin::Event::Timer::handleTimerEvent | ( | ) | [pure virtual] |
This method is overridden by a subclass and invoked when the timer expires.
This method will be invoked by the main event loop on whatever thread is running the Event::Loop.
Implemented in LogCabin::RPC::ClientSession::Timer, LogCabin::Event::Loop::NullTimer, and LogCabin::RPC::anonymous_namespace{ClientSession.cc}::TimerNotifier.
void LogCabin::Event::Timer::schedule | ( | uint64_t | nanoseconds | ) |
Start the timer for an absolute point in time.
If the timeout is in the past, the timer will trigger immediately once the event loop runs.
timeout | The timer will trigger once this timeout has past. If the timer was already scheduled, the old time is forgotten. |
void LogCabin::Event::Timer::deschedule | ( | ) |
Stop the timer from calling handleTimerEvent().
This will cancel the current timer, if any, so that handleTimerEvent() is not called until the next time it is scheduled.
This method behaves in a friendly way when called concurrently with the timer firing:
bool LogCabin::Event::Timer::isScheduled | ( | ) | const [private] |
Returns true if the timer has been scheduled and has not yet fired.
void LogCabin::Event::Timer::handleFileEvent | ( | uint32_t | events | ) | [private, virtual] |