diff --git a/common/timeout.c b/common/timeout.c index d4b4b480f..475733e02 100644 --- a/common/timeout.c +++ b/common/timeout.c @@ -31,7 +31,24 @@ struct oneshot *new_reltimer_(struct timers *timers, return t; } -void *reltimer_arg(struct oneshot *t) +struct oneshot *new_abstimer_(struct timers *timers, + const tal_t *ctx, + struct timemono expiry, + void (*cb)(void *), void *arg) +{ + struct oneshot *t = tal(ctx, struct oneshot); + + t->cb = cb; + t->arg = arg; + t->timers = timers; + timer_init(&t->timer); + timer_addmono(timers, &t->timer, expiry); + tal_add_destructor(t, destroy_timer); + + return t; +} + +void *oneshot_arg(struct oneshot *t) { return t->arg; } diff --git a/common/timeout.h b/common/timeout.h index 55b1a4b63..0277a0723 100644 --- a/common/timeout.h +++ b/common/timeout.h @@ -15,8 +15,16 @@ struct oneshot *new_reltimer_(struct timers *timers, new_reltimer_((timers), (ctx), (relexpire), \ typesafe_cb(void, void *, (func), (arg)), (arg)) +struct oneshot *new_abstimer_(struct timers *timers, + const tal_t *ctx, + struct timemono expiry, + void (*cb)(void *), void *arg); +#define new_abstimer(timers, ctx, expiry, func, arg) \ + new_abstimer_((timers), (ctx), (expiry), \ + typesafe_cb(void, void *, (func), (arg)), (arg)) + /* Get timer arg. */ -void *reltimer_arg(struct oneshot *t); +void *oneshot_arg(struct oneshot *t); void timer_expired(struct timer *timer);