|
E-MailRelay
|
A singleton which maintains a list of all Timer objects, and interfaces to the event loop on their behalf. More...
#include <gtimerlist.h>
Classes | |
| class | NoThrow |
| Overload discriminator class for TimerList. More... | |
Public Member Functions | |
| TimerList () | |
| Default constructor. | |
| ~TimerList () | |
| Destructor. Any expired timers have their timeouts called. | |
| void | add (TimerBase &, ExceptionHandler &) |
| Adds a timer. | |
| void | remove (TimerBase &) |
| Removes a timer from the list. | |
| void | update (TimerBase &) |
| Called when a timer changes its value. | |
| G::EpochTime | interval (bool &infinite) const |
| Returns the interval to the first timer expiry. More... | |
| void | doTimeouts () |
| Triggers the timeout callbacks of any expired timers. More... | |
| std::string | report () const |
| Returns a line of text reporting the status of the timer list. More... | |
| void | disarm (ExceptionHandler *) |
| Resets any matching ExceptionHandler pointers. | |
Static Public Member Functions | |
| static bool | exists () |
| Returns true if instance() exists. | |
| static TimerList * | instance (const NoThrow &) |
| Singleton access. Returns nullptr if none. | |
| static TimerList & | instance () |
| Singleton access. Throws an exception if none. | |
A singleton which maintains a list of all Timer objects, and interfaces to the event loop on their behalf.
Event loops that can do a timed-wait should call TimerList::interval() to determine how long to wait before the first G::Timer goes off. If the timed-wait times-out or if the interval was zero then they must call TimerList::doTimeouts().
Event loops that cannot do timed waits efficiently (ie. the traditional Windows message queue) have their setTimeout() method called by this class and they are expected to call doTimeouts() when the event-loop timer expires.
In both models there can be a race where this class sees no expired timers in doTimeouts(), perhaps because the system clock is being stretched. However, the next interval() or setTimer() time will be very small and the race will resolve itself naturally.
If a timer callback throws an exception then the associated exception handler is called. This is the same behaviour as in the EventHandlerList. This is made safe even if the event handler object is destroyed by the original exception because of the disarm() mechanism.
Definition at line 61 of file gtimerlist.h.
| void GNet::TimerList::doTimeouts | ( | ) |
Triggers the timeout callbacks of any expired timers.
Called by the event loop (GNet::EventLoop).
Definition at line 152 of file gtimerlist.cpp.
| G::EpochTime GNet::TimerList::interval | ( | bool & | infinite | ) | const |
Returns the interval to the first timer expiry.
The 'infinite' value is set to true if there are no timers running.
Definition at line 114 of file gtimerlist.cpp.
| std::string GNet::TimerList::report | ( | ) | const |
Returns a line of text reporting the status of the timer list.
Used in debugging and diagnostics.
Definition at line 194 of file gtimerlist.cpp.
1.8.9.1