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) {