diff options
author | michael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2009-11-15 06:49:13 +0000 |
---|---|---|
committer | michael <michael@3ae390bd-cb1e-0410-b409-cd5a39f66f1f> | 2009-11-15 06:49:13 +0000 |
commit | 3f6579900c3f3c7175209d7411d4ae87deabc48b (patch) | |
tree | ac273e2b4f9f1ad94aae865207d75efdac9a54e0 /timer.c | |
parent | 11ebe1024fd877cc908523fef2d6240be010fadb (diff) | |
download | lcd4linux-3f6579900c3f3c7175209d7411d4ae87deabc48b.tar.gz |
event plugin and dbus interface by Ed Martin
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1053 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to '')
-rw-r--r-- | timer.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -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) { |