From 931e3d51d96b2afd5a716c06238ae226c0641c69 Mon Sep 17 00:00:00 2001 From: Dariusz Stojaczyk Date: Mon, 17 Jul 2017 10:55:01 +0200 Subject: [PATCH] util: call for_each_channel completion in original thread As specified in the doc of spdk_for_each_channel: ``` Once 'fn' has been called on each channel, 'cpl' will be called on the thread that spdk_for_each_channel was initially called from. ``` Fixes: ff87d29cc313 ("io_channel: Add mechanism to call a function on each channel") Change-Id: Ic60b061ec402672f510d99697943e96ff9a73417 Signed-off-by: Dariusz Stojaczyk Reviewed-on: https://review.gerrithub.io/369719 Reviewed-by: Ben Walker Reviewed-by: Daniel Verkamp Tested-by: SPDK Automated Test System --- lib/util/io_channel.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/util/io_channel.c b/lib/util/io_channel.c index 355878496..ca5e6e659 100644 --- a/lib/util/io_channel.c +++ b/lib/util/io_channel.c @@ -322,6 +322,15 @@ struct call_channel { spdk_channel_for_each_cpl cpl; }; +static void +_call_completion(void *ctx) +{ + struct call_channel *ch_ctx = ctx; + + ch_ctx->cpl(ch_ctx->io_device, ch_ctx->ctx); + free(ch_ctx); +} + static void _call_channel(void *ctx) { @@ -351,8 +360,7 @@ _call_channel(void *ctx) pthread_mutex_unlock(&g_devlist_mutex); - ch_ctx->cpl(ch_ctx->io_device, ch_ctx->ctx); - free(ch_ctx); + spdk_thread_send_msg(ch_ctx->orig_thread, _call_completion, ch_ctx); } void