mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
8375857116
Also, we split the more sophisticated json_add helpers to avoid pulling in everything into lightning-cli, and unify the routines to print struct short_channel_id (it's ':', not '/' too). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
43 lines
886 B
C
43 lines
886 B
C
#include "timeout.h"
|
|
#include <common/utils.h>
|
|
|
|
struct oneshot {
|
|
struct timers *timers;
|
|
struct timer timer;
|
|
void (*cb)(void *);
|
|
void *arg;
|
|
};
|
|
|
|
static void remove_timer(struct oneshot *t)
|
|
{
|
|
timer_del(t->timers, &t->timer);
|
|
}
|
|
|
|
struct oneshot *new_reltimer_(struct timers *timers,
|
|
const tal_t *ctx,
|
|
struct timerel relexpiry,
|
|
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_addrel(timers, &t->timer, relexpiry);
|
|
tal_add_destructor(t, remove_timer);
|
|
|
|
return t;
|
|
}
|
|
|
|
void timer_expired(tal_t *ctx, struct timer *timer)
|
|
{
|
|
struct oneshot *t = container_of(timer, struct oneshot, timer);
|
|
const tal_t *tmpctx = tal_tmpctx(ctx);
|
|
|
|
/* If it doesn't free itself, freeing tmpctx will do it */
|
|
tal_steal(tmpctx, t);
|
|
t->cb(t->arg);
|
|
tal_free(tmpctx);
|
|
}
|