core-lightning/daemon/timeout.c
Rusty Russell 4bed6c8c67 controlled_time: remove
We don't need it for testing at the moment, and if we do it'll have
to change to relative anyway now we're going to use time_mono().

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2016-11-09 18:54:15 +10:30

45 lines
1020 B
C

#include "lightningd.h"
#include "timeout.h"
#include "utils.h"
struct oneshot {
struct lightningd_state *dstate;
struct timer timer;
void (*cb)(void *);
void *arg;
};
static void remove_timer(struct oneshot *t)
{
timer_del(&t->dstate->timers, &t->timer);
}
struct oneshot *new_reltimer_(struct lightningd_state *dstate,
const tal_t *ctx,
struct timerel relexpiry,
void (*cb)(void *), void *arg)
{
struct oneshot *t = tal(ctx, struct oneshot);
struct timeabs expiry = timeabs_add(time_now(), relexpiry);
t->cb = cb;
t->arg = arg;
t->dstate = dstate;
timer_init(&t->timer);
timer_add(&dstate->timers, &t->timer, expiry);
tal_add_destructor(t, remove_timer);
return t;
}
void timer_expired(struct lightningd_state *dstate, struct timer *timer)
{
struct oneshot *t = container_of(timer, struct oneshot, timer);
const tal_t *tmpctx = tal_tmpctx(dstate);
/* If it doesn't free itself, freeing tmpctx will do it */
tal_steal(tmpctx, t);
t->cb(t->arg);
tal_free(tmpctx);
}