X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2Futil%2Ftimer.h;h=250e7e0bd33d16894dad86d347e3e8caff8c173d;hb=f8f6e7f277a6e09fb4a9fa7db532867d51d229be;hp=23aea08d53b32406de5d6320f84bd70d90a495c1;hpb=35e206acc0a7b9dca7611fe4a7e17c7acc381ad0;p=chaz%2Ftint2 diff --git a/src/util/timer.h b/src/util/timer.h index 23aea08..250e7e0 100644 --- a/src/util/timer.h +++ b/src/util/timer.h @@ -22,31 +22,42 @@ #include extern GSList* timeout_list; -extern struct timespec next_timeout; +extern struct timeval next_timeout; -struct timeout { - int interval_msec; - struct timespec timeout_expires; - void (*_callback)(); -}; +typedef struct _timeout timeout; // timer functions +/** + * Single shot timer (i.e. timer with interval_msec == 0) are deleted automatically as soon as they expire + * i.e. you do not need to stop them, however it is safe to call stop_timeout for these timers. + * Periodic timeouts are aligned to each other whenever possible, i.e. one interval_msec is an + * integral multiple of the other. +**/ + +/** default global data **/ +void default_timeout(); + +/** freed memory : stops all timeouts **/ +void cleanup_timeout(); + /** installs a timeout with the first timeout of 'value_msec' and then a periodic timeout with - * 'interval_msec'. '_callback' is the callback function when the timer reaches the timeout. - * returns a pointer to the timeout, which is needed for stopping it again **/ -const struct timeout* add_timeout(int value_msec, int interval_msec, void (*_callback)()); + * 'interval_msec'. '_callback' is the callback function when the timer reaches the timeout. + * returns a pointer to the timeout, which is needed for stopping it again +**/ +timeout* add_timeout(int value_msec, int interval_msec, void (*_callback)(void*), void* arg); -void change_timeout(const struct timeout* t, int value_msec, int interval_msec, void (*_callback)()); +/** changes timeout 't'. If timeout 't' does not exist, nothing happens **/ +void change_timeout(timeout* t, int value_msec, int interval_msec, void (*_callback)(void*), void* arg); /** stops the timeout 't' **/ -void stop_timeout(const struct timeout* t); - -/** stops all timeouts **/ -void stop_all_timeouts(); +void stop_timeout(timeout* t); +/** update_next_timeout updates next_timeout to the value, when the next installed timeout will expire **/ void update_next_timeout(); + +/** Callback of all expired timeouts **/ void callback_timeout_expired(); #endif // TIMER_H