common: add routine for absolute timeouts (vs. relative).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-01-08 23:57:29 +10:30
parent e37a638c0c
commit 1f608acd4e
2 changed files with 27 additions and 2 deletions

View File

@ -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;
}

View File

@ -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);