From 8203e68e24641fed30156c9d9d1cce074162f0ee Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 17 Nov 2022 06:10:53 +0000 Subject: [PATCH] thread: add spdk_thread_is_running() This function can be useful to query if a thread had spdk_thread_exit() called on it yet. Internally we have both EXITING and EXITED state - so !spdk_thread_is_running() can be used to detect a thread that is in either of those states. Signed-off-by: Jim Harris Change-Id: I2f6fb024a6b1bc895fdc5132c722abc10f5d30f9 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15512 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Aleksey Marchuk --- CHANGELOG.md | 3 +++ include/spdk/thread.h | 16 ++++++++++++++++ lib/thread/spdk_thread.map | 1 + lib/thread/thread.c | 6 ++++++ 4 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec835643e..f11b54132 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,9 @@ for writing and decoding of the the double data type. Added `spdk_thread_get_app_thread` which returns the first thread that was created using `spdk_thread_create`. +Added `spdk_thread_is_running`. This returns `true` for a running thread, or `false` if +its exit process has started using `spdk_thread_exit`. + ## v22.09 ### accel diff --git a/include/spdk/thread.h b/include/spdk/thread.h index 168f46044..03b38e426 100644 --- a/include/spdk/thread.h +++ b/include/spdk/thread.h @@ -285,12 +285,28 @@ int spdk_thread_exit(struct spdk_thread *thread); /** * Returns whether the thread is marked as exited. * + * A thread is exited only after it has spdk_thread_exit() called on it, and + * it has been polled until any outstanding operations targeting this + * thread have completed. This may include poller unregistrations, io channel + * unregistrations, or outstanding spdk_thread_send_msg calls. + * * \param thread The thread to query. * * \return true if marked as exited, false otherwise. */ bool spdk_thread_is_exited(struct spdk_thread *thread); +/** + * Returns whether the thread is still running. + * + * A thread is considered running until it has * spdk_thread_exit() called on it. + * + * \param thread The thread to query. + * + * \return true if still running, false otherwise. + */ +bool spdk_thread_is_running(struct spdk_thread *thread); + /** * Destroy a thread, releasing all of its resources. May only be called * on a thread previously marked as exited. diff --git a/lib/thread/spdk_thread.map b/lib/thread/spdk_thread.map index 0e48a2c3c..5aeab5a75 100644 --- a/lib/thread/spdk_thread.map +++ b/lib/thread/spdk_thread.map @@ -9,6 +9,7 @@ spdk_thread_get_app_thread; spdk_set_thread; spdk_thread_exit; + spdk_thread_is_running; spdk_thread_is_exited; spdk_thread_destroy; spdk_thread_get_ctx; diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 510d1079c..1342038f0 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -594,6 +594,12 @@ spdk_thread_exit(struct spdk_thread *thread) return 0; } +bool +spdk_thread_is_running(struct spdk_thread *thread) +{ + return thread->state == SPDK_THREAD_STATE_RUNNING; +} + bool spdk_thread_is_exited(struct spdk_thread *thread) {