You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
886 B
43 lines
886 B
9 years ago
|
#include "timeout.h"
|
||
7 years ago
|
#include <common/utils.h>
|
||
9 years ago
|
|
||
9 years ago
|
struct oneshot {
|
||
8 years ago
|
struct timers *timers;
|
||
9 years ago
|
struct timer timer;
|
||
9 years ago
|
void (*cb)(void *);
|
||
|
void *arg;
|
||
|
};
|
||
|
|
||
9 years ago
|
static void remove_timer(struct oneshot *t)
|
||
9 years ago
|
{
|
||
8 years ago
|
timer_del(t->timers, &t->timer);
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
struct oneshot *new_reltimer_(struct timers *timers,
|
||
9 years ago
|
const tal_t *ctx,
|
||
8 years ago
|
struct timerel relexpiry,
|
||
9 years ago
|
void (*cb)(void *), void *arg)
|
||
9 years ago
|
{
|
||
9 years ago
|
struct oneshot *t = tal(ctx, struct oneshot);
|
||
|
|
||
|
t->cb = cb;
|
||
|
t->arg = arg;
|
||
8 years ago
|
t->timers = timers;
|
||
9 years ago
|
timer_init(&t->timer);
|
||
8 years ago
|
timer_addrel(timers, &t->timer, relexpiry);
|
||
9 years ago
|
tal_add_destructor(t, remove_timer);
|
||
|
|
||
|
return t;
|
||
9 years ago
|
}
|
||
|
|
||
8 years ago
|
void timer_expired(tal_t *ctx, struct timer *timer)
|
||
9 years ago
|
{
|
||
|
struct oneshot *t = container_of(timer, struct oneshot, timer);
|
||
8 years ago
|
const tal_t *tmpctx = tal_tmpctx(ctx);
|
||
9 years ago
|
|
||
9 years ago
|
/* If it doesn't free itself, freeing tmpctx will do it */
|
||
|
tal_steal(tmpctx, t);
|
||
|
t->cb(t->arg);
|
||
8 years ago
|
tal_free(tmpctx);
|
||
9 years ago
|
}
|