Commit c350ef68 authored by Artsiom Koltun's avatar Artsiom Koltun Committed by Tomasz Zawadzki
Browse files

examples: keep global channel for thread example



Thread example demonstrates sending of a message to all channels.
However, exemplary channel was destroyed right after creation and
no channels existed. Thus, io_device_send_msg_fn was never called.

Keep channel active in global variable until io device is
unregistered to showcase threading capabilities.

Change-Id: Ie8a3037d4dd23686d5157d8412d8c3336d15496b
Signed-off-by: default avatarArtsiom Koltun <artsiom.koltun@intel.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26325


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarChangpeng Liu <changpeliu@tencent.com>
Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
parent 39cd694a
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ static uint64_t g_for_each_thread_poller_counter;
static uint64_t g_for_each_channel_poller_counter;
static uint64_t g_thread_poll_cnt;
static uint64_t g_io_channel_cnt;
static struct spdk_io_channel *g_io_channel = NULL;
static struct spdk_poller *g_active_poller = NULL, *g_timed_poller = NULL;
static struct spdk_poller *g_timed_for_each_thread = NULL, *g_timed_for_each_channel = NULL;

@@ -289,17 +290,13 @@ destroy_cb(void *io_device, void *ctx_buf)
static void
app_thread_register_io_device(void *arg)
{
	struct spdk_io_channel *ch0 = NULL;

	printf("Registering a new IO device.\n");
	spdk_io_device_register(&g_io_channel_cnt, create_cb, destroy_cb,
				sizeof(int), NULL);

	/* Get a reference pointer to IO channel. */
	ch0 = spdk_get_io_channel(&g_io_channel_cnt);
	assert(ch0 != NULL);
	/* Put (away) the reference pointer. */
	spdk_put_io_channel(ch0);
	g_io_channel = spdk_get_io_channel(&g_io_channel_cnt);
	assert(g_io_channel != NULL);
}

static void
@@ -318,6 +315,8 @@ app_thread_unregister_io_device(void *arg)
{
	printf("Unregistering IO device...\n");

	spdk_put_io_channel(g_io_channel);

	spdk_io_device_unregister(&g_io_channel_cnt, unregister_cb);
}