mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
libplugin: allow freeing in timer callback, clarify docs, allow nested timers.
1. Allow timers to be freed in their callback. 2. Clarify in header that we have to terminate our timer with timer_finished() eventually. 3. We don't currently have plugins with more than one outstanding timer, but it certainly would be possible, so fix in_timer to be a counter. Suggested-by: @ZmnSCPxj Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
9b61c19a20
commit
6a8cd9a016
@@ -29,7 +29,7 @@ static STRMAP(const char *) usagemap;
|
||||
|
||||
/* Timers */
|
||||
static struct timers timers;
|
||||
static bool in_timer;
|
||||
static size_t in_timer;
|
||||
|
||||
bool deprecated_apis;
|
||||
|
||||
@@ -244,8 +244,8 @@ command_done_raw(struct command *cmd,
|
||||
|
||||
struct command_result *timer_complete(void)
|
||||
{
|
||||
assert(in_timer);
|
||||
in_timer = false;
|
||||
assert(in_timer > 0);
|
||||
in_timer--;
|
||||
return &complete;
|
||||
}
|
||||
|
||||
@@ -603,9 +603,10 @@ static void call_plugin_timer(struct plugin_conn *rpc, struct timer *timer)
|
||||
{
|
||||
struct plugin_timer *t = container_of(timer, struct plugin_timer, timer);
|
||||
|
||||
in_timer = true;
|
||||
in_timer++;
|
||||
/* Free this if they don't. */
|
||||
tal_steal(tmpctx, t);
|
||||
t->cb();
|
||||
tal_free(t);
|
||||
}
|
||||
|
||||
static void destroy_plugin_timer(struct plugin_timer *timer)
|
||||
|
||||
Reference in New Issue
Block a user