From 4e7bb83e780ea4b402bd2051ba4007cd8ad19a4e Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Wed, 13 Feb 2019 11:17:49 -0700 Subject: [PATCH] thread: Add a function to get the thread from a context This is the inverse of spdk_thread_get_ctx. Change-Id: I81541ff1687cfea358cb7046caf69982c38f6a38 Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/c/444455 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- include/spdk/thread.h | 10 ++++++++++ lib/thread/thread.c | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/spdk/thread.h b/include/spdk/thread.h index a5778e7ff..724fa46eb 100644 --- a/include/spdk/thread.h +++ b/include/spdk/thread.h @@ -222,6 +222,16 @@ void spdk_thread_exit(struct spdk_thread *thread); */ void *spdk_thread_get_ctx(struct spdk_thread *thread); +/** + * Return the thread object associated with the context handle previously + * obtained by calling spdk_thread_get_ctx(). + * + * \param ctx A context previously obtained by calling spdk_thread_get_ctx() + * + * \return The associated thread. + */ +struct spdk_thread *spdk_thread_get_from_ctx(void *ctx); + /** * Perform one iteration worth of processing on the thread. This includes * both expired and continuous pollers as well as messages. diff --git a/lib/thread/thread.c b/lib/thread/thread.c index c0fb191b7..d3ad66c81 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -342,6 +342,19 @@ spdk_thread_get_ctx(struct spdk_thread *thread) return NULL; } +struct spdk_thread * +spdk_thread_get_from_ctx(void *ctx) +{ + if (ctx == NULL) { + assert(false); + return NULL; + } + + assert(g_ctx_sz > 0); + + return SPDK_CONTAINEROF(ctx, struct spdk_thread, ctx); +} + static inline uint32_t _spdk_msg_queue_run_batch(struct spdk_thread *thread, uint32_t max_msgs) {