Browse Source
For better or worse, the ccan/timer structure is completely minimal, and designed to be wrapped inside a container structure. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>ppa-0.6.1
Rusty Russell
9 years ago
5 changed files with 54 additions and 2 deletions
@ -0,0 +1,18 @@ |
|||
#include "lightningd.h" |
|||
#include "timeout.h" |
|||
|
|||
void init_timeout_(struct timeout *t, unsigned int interval, |
|||
void (*cb)(void *), void *arg) |
|||
{ |
|||
timer_init(&t->timer); |
|||
t->interval = time_from_sec(interval); |
|||
t->cb = cb; |
|||
t->arg = arg; |
|||
} |
|||
|
|||
void refresh_timeout(struct lightningd_state *state, struct timeout *t) |
|||
{ |
|||
timer_del(&state->timers, &t->timer); |
|||
timer_add(&state->timers, &t->timer, |
|||
timeabs_add(time_now(), t->interval)); |
|||
} |
@ -0,0 +1,27 @@ |
|||
#ifndef LIGHTNING_DAEMON_TIMEOUT_H |
|||
#define LIGHTNING_DAEMON_TIMEOUT_H |
|||
#include "config.h" |
|||
|
|||
#include <ccan/time/time.h> |
|||
#include <ccan/timer/timer.h> |
|||
#include <ccan/typesafe_cb/typesafe_cb.h> |
|||
|
|||
struct timeout { |
|||
struct timer timer; |
|||
struct timerel interval; |
|||
void (*cb)(void *); |
|||
void *arg; |
|||
}; |
|||
|
|||
struct lightningd_state; |
|||
|
|||
void init_timeout_(struct timeout *t, unsigned int interval, |
|||
void (*cb)(void *), void *arg); |
|||
|
|||
void refresh_timeout(struct lightningd_state *state, struct timeout *t); |
|||
|
|||
#define init_timeout(t, interval, func, arg) \ |
|||
init_timeout_((t), (interval), \ |
|||
typesafe_cb(void, void *, (func), (arg)), (arg)) |
|||
|
|||
#endif /* LIGHTNING_DAEMON_TIMEOUT_H */ |
Loading…
Reference in new issue