aboutsummaryrefslogtreecommitdiffstats
path: root/timer.c
diff options
context:
space:
mode:
authormzuther <mzuther@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2010-02-06 11:29:12 +0000
committermzuther <mzuther@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2010-02-06 11:29:12 +0000
commit43aef95679f4be26c5fb99c03d18118de3006f03 (patch)
tree552513222181900328194bee94f7ecdc63a6b4f4 /timer.c
parent15d08f4e90531ed35cea32538a7bd9e7a6ae7e32 (diff)
downloadlcd4linux-43aef95679f4be26c5fb99c03d18118de3006f03.tar.gz
timer.c: exchanged "proprietary code" with timeradd() and timersub() functions
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1102 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to 'timer.c')
-rw-r--r--timer.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/timer.c b/timer.c
index 174e1e3..3ae864b 100644
--- a/timer.c
+++ b/timer.c
@@ -77,13 +77,11 @@ int nTimers = 0;
static void timer_inc(struct timeval *tv, const int msec)
{
- tv->tv_sec += msec / 1000;
- tv->tv_usec += (msec - 1000 * (msec / 1000)) * 1000;
+ struct timeval diff;
+ diff.tv_sec = msec / 1000;
+ diff.tv_usec = (msec % 1000) * 1000;
- if (tv->tv_usec >= 1000000) {
- tv->tv_usec -= 1000000;
- tv->tv_sec++;
- }
+ timeradd(tv, &diff, tv);
}
int timer_remove(void (*callback) (void *data), void *data)
@@ -206,14 +204,12 @@ int timer_process(struct timespec *delay)
}
/* delay until next timer event */
- delay->tv_sec = Timers[min].when.tv_sec - now.tv_sec;
- delay->tv_nsec = Timers[min].when.tv_usec - now.tv_usec;
- if (delay->tv_nsec < 0) {
- delay->tv_sec--;
- delay->tv_nsec += 1000000;
- }
- /* nanoseconds!! */
- delay->tv_nsec *= 1000;
+ struct timeval diff;
+ timersub(&Timers[min].when, &now, &diff);
+
+ delay->tv_sec = diff.tv_sec;
+ /* microseconds to nanoseconds!! */
+ delay->tv_nsec = diff.tv_usec * 1000;
/* check if date changed */
if ((delay->tv_sec) > CLOCK_SKEW_DETECT_TIME_IN_S) {