X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=openbox%2Ftimer.c;h=b49f4dea6aa269954de2918d8650ddfec62ab034;hb=c8fa3a6028a4187675d4ffeee07485ed3caae38b;hp=0cec366f16a9eefa90158a7b60733c0496657e3f;hpb=f8a47de5ec444c452093371e3db16857eb39a490;p=chaz%2Fopenbox diff --git a/openbox/timer.c b/openbox/timer.c index 0cec366f..b49f4dea 100644 --- a/openbox/timer.c +++ b/openbox/timer.c @@ -8,14 +8,23 @@ static GTimeVal now; static GTimeVal ret_wait; static GSList *timers; /* nearest timer is at the top */ -#define NEAREST_TIMEOUT (((Timer*)timers->data)->timeout) +#define NEAREST_TIMEOUT (((ObTimer*)timers->data)->timeout) -static void insert_timer(Timer *self) +static long timecompare(GTimeVal *a, GTimeVal *b) +{ + long r; + + if ((r = b->tv_sec - a->tv_sec)) return r; + return b->tv_usec - a->tv_usec; + +} + +static void insert_timer(ObTimer *self) { GSList *it; for (it = timers; it != NULL; it = it->next) { - Timer *t = it->data; - if (!timercmp(&self->timeout, &t->timeout, >)) { + ObTimer *t = it->data; + if (timecompare(&self->timeout, &t->timeout) <= 0) { timers = g_slist_insert_before(timers, it, self); break; } @@ -40,9 +49,9 @@ void timer_shutdown() timers = NULL; } -Timer *timer_start(long delay, TimeoutHandler cb, void *data) +ObTimer *timer_start(long delay, ObTimeoutHandler cb, void *data) { - Timer *self = g_new(Timer, 1); + ObTimer *self = g_new(ObTimer, 1); self->delay = delay; self->action = cb; self->data = data; @@ -55,7 +64,7 @@ Timer *timer_start(long delay, TimeoutHandler cb, void *data) return self; } -void timer_stop(Timer *self) +void timer_stop(ObTimer *self) { self->del_me = TRUE; } @@ -87,7 +96,7 @@ void timer_dispatch(GTimeVal **wait) g_get_current_time(&now); while (timers != NULL) { - Timer *curr = timers->data; /* get the top element */ + ObTimer *curr = timers->data; /* get the top element */ /* since timer_stop doesn't actually free the timer, we have to do our real freeing in here. */ @@ -99,7 +108,7 @@ void timer_dispatch(GTimeVal **wait) /* the queue is sorted, so if this timer shouldn't fire, none are ready */ - if (!timercmp(&now, &NEAREST_TIMEOUT, >)) + if (timecompare(&NEAREST_TIMEOUT, &now) <= 0) break; /* we set the last fired time to delay msec after the previous firing,