timer, timer_impl

    // Members of dasynq::event_loop<T> instantiation:

    class timer;

    template <class Derived> class timer_impl; // : public timer;

timer

Brief: timer is a member type of the event_loop template class. It represents an event watcher which receives callbacks upon the passing of a certain period of time, or at a certain time, against either the system clock (which can potentially have its time altered during system operation) or a monotonic clock which is not adjustable. The timer class should not be subclassed directly; the timer_impl template provides a means for subclassing.

Members

Types

Constructors

Functions

Details and Usage

A timer represents a timer which expires at some point in time and an associated watcher which receives callback notifications for timer expiry. Timers can be one-shot (stop automatically after expiry) or periodic (on expiry, the timeout is incremented by a specified interval).

A timer can run on one of two clocks, specified by a clock_type. The SYSTEM clock is the current "wall clock" time according to the system; its time value should normally only increase at a constant rate, but may be altered by large amounts in either direction if the system clock is altered. The MONOTONIC clock always increments at a constant rate and cannot be altered otherwise.

When a timer is set, the initial timeout can be specified either as an absolute time, or to a time that is relative to the current time. While setting relative times to the SYSTEM clock is supported, be aware that it rarely makes sense to do so; the timer is not guaranteed to expire after the specified interval (if the system clock is adjusted, the adjustment will also be applied to the timeout). Use a timer against the MONOTONIC clock if you need a specific interval of time.

Subclassing timer

To specify callback behaviour, timer can be subclassed — however, it should not be directly subclassed; instead, use the timer_impl implementation wrapper template.


timer_impl

Brief: The timer_impl provides a basis for implementing timer, using the "curiously recurring template pattern". Instead of subclassing timer directly, subclass an instantiation of timer_impl with the template parameter specified as the subclass itself. For example:

class my_timer : public timer_impl<my_timer>
{
    // ...
}

Details and Usage

The callback function must be provided in the subclass and named fd_event, with a signature compatible with the following:

rearm timer_expiry(event_loop_t &loop, int expiry_count);

The timer_expiry function must be public, but need not be virtual. It will be called with the following parameters:

The return value specifies the rearm action.

An timer_impl instantiation has no public or protected members, other than those inherited from timer_watcher, which it publicly derives from.