Commit c9da0aec authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

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: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I8b94261575e770485b33c0b37e76e770b77b417c
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1639


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 78accbf4
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -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);
		}
		spdk_thread_destroy(thread);
	}

+3 −3
Original line number Diff line number Diff line
@@ -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",
		SPDK_INFOLOG(SPDK_LOG_THREAD, "thread %s is already marked as exited\n",
			     thread->name);
		return -EINVAL;
		return 0;
	}

	TAILQ_FOREACH(poller, &thread->active_pollers, tailq) {
+2 −4
Original line number Diff line number Diff line
@@ -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);
		}
		spdk_thread_destroy(g_ut_threads[i].thread);
		g_ut_threads[i].thread = NULL;
	}
+2 −2
Original line number Diff line number Diff line
@@ -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.