kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 7b3224ad30ab38b96588db3a7170ca9554cfba43
parent a20fb00789120182ebdd91c7006bdfbb3f19d421
Author: Joris Vink <joris@coders.se>
Date:   Thu,  6 Aug 2015 08:20:41 +0200

Remove 'behind' argument from timers.

Also calculate next run for a timer as now + interval
instead of last nextrun + interval - delta.

Diffstat:
includes/kore.h | 6+++---
src/timer.c | 9++++-----
2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/includes/kore.h b/includes/kore.h @@ -360,7 +360,7 @@ struct kore_timer { u_int64_t interval; int flags; void *arg; - void (*cb)(void *, u_int64_t, u_int64_t); + void (*cb)(void *, u_int64_t); TAILQ_ENTRY(kore_timer) list; }; @@ -449,8 +449,8 @@ struct kore_auth *kore_auth_lookup(const char *); void kore_timer_init(void); u_int64_t kore_timer_run(u_int64_t); void kore_timer_remove(struct kore_timer *); -struct kore_timer *kore_timer_add(void (*cb)(void *, u_int64_t, - u_int64_t), u_int64_t, void *, int); +struct kore_timer *kore_timer_add(void (*cb)(void *, u_int64_t), + u_int64_t, void *, int); int kore_tls_sni_cb(SSL *, int *, void *); int kore_server_bind(const char *, const char *); diff --git a/src/timer.c b/src/timer.c @@ -28,7 +28,7 @@ kore_timer_init(void) } struct kore_timer * -kore_timer_add(void (*cb)(void *, u_int64_t, u_int64_t), u_int64_t interval, +kore_timer_add(void (*cb)(void *, u_int64_t), u_int64_t interval, void *arg, int flags) { struct kore_timer *timer, *t; @@ -63,7 +63,7 @@ u_int64_t kore_timer_run(u_int64_t now) { struct kore_timer *timer, *t; - u_int64_t next_timer, delta; + u_int64_t next_timer; next_timer = 100; @@ -74,13 +74,12 @@ kore_timer_run(u_int64_t now) } TAILQ_REMOVE(&kore_timers, timer, list); - delta = now - timer->nextrun; - timer->cb(timer->arg, now, delta); + timer->cb(timer->arg, now); if (timer->flags & KORE_TIMER_ONESHOT) { kore_mem_free(timer); } else { - timer->nextrun += timer->interval - delta; + timer->nextrun = now + timer->interval; TAILQ_FOREACH(t, &kore_timers, list) { if (t->nextrun > timer->nextrun) { TAILQ_INSERT_BEFORE(t, timer, list);