From 3f6579900c3f3c7175209d7411d4ae87deabc48b Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 15 Nov 2009 06:49:13 +0000 Subject: event plugin and dbus interface by Ed Martin git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1053 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- timer.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'timer.c') diff --git a/timer.c b/timer.c index 751a7e1..5ac2965 100644 --- a/timer.c +++ b/timer.c @@ -31,6 +31,12 @@ * int timer_process (struct timespec *delay); * process timer queue * + * int timer_remove(void (*callback) (void *data), void *data); + * remove a timer with given callback and data + * + * int timer_add_late(void (*callback) (void *data), void *data, const int interval, const int one_shot) + * same as timer_add, but the one shot does not fire now (useful for scheduling things) + * * void timer_exit(); * release all timers * @@ -80,6 +86,38 @@ static void timer_inc(struct timeval *tv, const int msec) } } +int timer_remove(void (*callback) (void *data), void *data) +{ + int i; + for (i = 0; i < nTimers; i++) { + if (Timers[i].callback == callback && Timers[i].data == data && Timers[i].active) { + Timers[i].active = 0; + return 0; + } + } + return -1; +} + +int timer_add_late(void (*callback) (void *data), void *data, const int interval, const int one_shot) +{ + if (!timer_add(callback, data, interval, 1)) { + return -1; + } + if (one_shot) { + return 0; + } + int i; + for (i = 0; i < nTimers; i++) { + if (Timers[i].callback == callback && Timers[i].data == data && Timers[i].active + && Timers[i].interval == interval && Timers[i].one_shot) { + //we forced it to one_shot when adding to make it late (which gives us the alternate behavior) + Timers[i].one_shot = one_shot; + return 0; + } + } + + return -1; +} int timer_add(void (*callback) (void *data), void *data, const int interval, const int one_shot) { -- cgit v1.2.3