lib/thread: Ignore spdk_thread_exit() call after moving exited

Previously the caller had to check if thread is not exited when
it calls spdk_thread_exit().

Subsequent patches will change return type of spdk_thread_exit()
to void, and so include the check int spdk_thread_exit() in this
patch.

If spdk_thread_exit() is called when the thread is already exited,
collect INFOLOG and return normally.

This will make the next patch a little easier.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I8b94261575e770485b33c0b37e76e770b77b417c
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1639
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Shuhei Matsumoto 2020-04-03 08:28:46 +09:00 committed by Tomasz Zawadzki
parent 78accbf4e5
commit c9da0aecdc
4 changed files with 9 additions and 13 deletions

View File

@ -392,10 +392,8 @@ _spdk_reactor_run(void *arg)
assert(reactor->thread_count > 0);
reactor->thread_count--;
spdk_set_thread(thread);
if (!spdk_thread_is_exited(thread)) {
rc = spdk_thread_exit(thread);
assert(rc == 0);
}
rc = spdk_thread_exit(thread);
assert(rc == 0);
spdk_thread_destroy(thread);
}

View File

@ -325,9 +325,9 @@ spdk_thread_exit(struct spdk_thread *thread)
assert(tls_thread == thread);
if (thread->exit) {
SPDK_ERRLOG("thread %s is already marked as exited\n",
thread->name);
return -EINVAL;
SPDK_INFOLOG(SPDK_LOG_THREAD, "thread %s is already marked as exited\n",
thread->name);
return 0;
}
TAILQ_FOREACH(poller, &thread->active_pollers, tailq) {

View File

@ -107,10 +107,8 @@ free_threads(void)
for (i = 0; i < g_ut_num_threads; i++) {
set_thread(i);
if (!spdk_thread_is_exited(g_ut_threads[i].thread)) {
rc = spdk_thread_exit(g_ut_threads[i].thread);
assert(rc == 0);
}
rc = spdk_thread_exit(g_ut_threads[i].thread);
assert(rc == 0);
spdk_thread_destroy(g_ut_threads[i].thread);
g_ut_threads[i].thread = NULL;
}

View File

@ -852,13 +852,13 @@ thread_exit(void)
spdk_io_device_unregister(&g_device1, NULL);
poll_threads();
/* Test call spdk_thread_exit() is only once for a single thread. */
/* Test 2nd spdk_thread_exit() call is ignored. */
set_thread(3);
thread = spdk_get_thread();
CU_ASSERT(spdk_thread_exit(thread) == 0);
CU_ASSERT(spdk_thread_exit(thread) == -EINVAL);
CU_ASSERT(spdk_thread_exit(thread) == 0);
/* Test if spdk_thread_exit() fails when there is any registered poller,
* and if no poller is executed after the thread is marked as exited.