From c013322dc606e38961065bb529f21bedd0210690 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 12 Jun 2017 15:56:09 -0700 Subject: [PATCH] io_channel: add helper to get an I/O channel's thread This is faster than spdk_get_thread(), which iterates over all of the threads under a lock until it finds the current one. Change-Id: I957a68438efb5b7d632d2b9b1b567fed7714e02a Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/365079 Reviewed-by: Ben Walker Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris --- include/spdk/io_channel.h | 7 +++++++ lib/util/io_channel.c | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/include/spdk/io_channel.h b/include/spdk/io_channel.h index aea084a75..996037dec 100644 --- a/include/spdk/io_channel.h +++ b/include/spdk/io_channel.h @@ -78,6 +78,8 @@ void spdk_free_thread(void); /** * \brief Get a handle to the current thread. This handle may be passed * to other threads and used as the target of spdk_thread_send_msg(). + * + * \sa spdk_io_channel_get_thread() */ struct spdk_thread *spdk_get_thread(void); @@ -140,6 +142,11 @@ void spdk_put_io_channel(struct spdk_io_channel *ch); */ void *spdk_io_channel_get_ctx(struct spdk_io_channel *ch); +/** + * \brief Returns the spdk_thread associated with an I/O channel. + */ +struct spdk_thread *spdk_io_channel_get_thread(struct spdk_io_channel *ch); + /** * \brief Call 'fn' on each channel associated with io_device. This happens * asynchronously, so fn may be called after spdk_for_each_channel returns. diff --git a/lib/util/io_channel.c b/lib/util/io_channel.c index 8d1f30f62..5a3609cc4 100644 --- a/lib/util/io_channel.c +++ b/lib/util/io_channel.c @@ -296,6 +296,12 @@ spdk_io_channel_get_ctx(struct spdk_io_channel *ch) return (uint8_t *)ch + sizeof(*ch); } +struct spdk_thread * +spdk_io_channel_get_thread(struct spdk_io_channel *ch) +{ + return ch->thread; +} + struct call_channel { void *io_device; spdk_channel_msg fn;