From 3729ad9914cbd800e145b3fcc7926890ea505a84 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 18 Mar 2019 13:10:32 +1030 Subject: [PATCH] plugin: plugin_exclusive_loop helper to service one plugin synchronously. Signed-off-by: Rusty Russell --- lightningd/plugin.c | 18 ++++++++++++++++++ lightningd/plugin.h | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 4d84ab3f9..602ed9441 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -1053,3 +1053,21 @@ void plugin_request_send(struct plugin *plugin, * pointer here */ req->stream = NULL; } + +void *plugin_exclusive_loop(struct plugin *plugin) +{ + void *ret; + + io_conn_out_exclusive(plugin->stdin_conn, true); + io_conn_exclusive(plugin->stdout_conn, true); + + /* We don't service timers here, either! */ + ret = io_loop(NULL, NULL); + + io_conn_out_exclusive(plugin->stdin_conn, false); + if (io_conn_exclusive(plugin->stdout_conn, false)) + fatal("Still io_exclusive after removing plugin %s?", + plugin->cmd); + + return ret; +} diff --git a/lightningd/plugin.h b/lightningd/plugin.h index 47b118786..50e6e5dc2 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -79,6 +79,14 @@ void json_add_opt_plugins(struct json_stream *response, const struct plugins *plugins); +/** + * Used by db hooks which can't have any other I/O while talking to plugin. + * + * Returns output of io_loop() (ie. whatever gets passed to io_break() + * to end exclusive loop). + */ +void *plugin_exclusive_loop(struct plugin *plugin); + /** * Add a directory to the plugin path to automatically load plugins. */