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

lib/thread: Wait until thread_is_exited() is true by thread_poll() after thread_exit()



Following patches will require thread termination so that thread_exit()
will move thread to exiting, thread_poll() will move thread from
exiting to exited, thread_is_exited() will detect the threadis exited,
and then call thread_destroy().

So change all places as a preparation.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I6b2e8aee5ed7cd160a88b4c9aaed7d90bd9dac07
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1640


Community-CI: Broadcom CI
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent c9da0aec
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -156,6 +156,9 @@ spdk_fio_cleanup_thread(struct spdk_fio_thread *fio_thread)
	spdk_set_thread(fio_thread->thread);

	spdk_thread_exit(fio_thread->thread);
	while (!spdk_thread_is_exited(fio_thread->thread)) {
		spdk_thread_poll(fio_thread->thread, 0, 0);
	}
	spdk_thread_destroy(fio_thread->thread);
	free(fio_thread->iocq);
	free(fio_thread);
+3 −0
Original line number Diff line number Diff line
@@ -204,6 +204,9 @@ nvmf_reactor_run(void *arg)
		TAILQ_REMOVE(&nvmf_reactor->threads, lw_thread, link);
		spdk_set_thread(thread);
		spdk_thread_exit(thread);
		while (!spdk_thread_is_exited(thread)) {
			spdk_thread_poll(thread, 0, 0);
		}
		spdk_thread_destroy(thread);
	}
	pthread_mutex_unlock(&nvmf_reactor->mutex);
+3 −0
Original line number Diff line number Diff line
@@ -394,6 +394,9 @@ _spdk_reactor_run(void *arg)
		spdk_set_thread(thread);
		rc = spdk_thread_exit(thread);
		assert(rc == 0);
		while (!spdk_thread_is_exited(thread)) {
			spdk_thread_poll(thread, 0, 0);
		}
		spdk_thread_destroy(thread);
	}

+7 −2
Original line number Diff line number Diff line
@@ -103,13 +103,18 @@ void
free_threads(void)
{
	uint32_t i;
	struct spdk_thread *thread;
	int rc __attribute__((unused));

	for (i = 0; i < g_ut_num_threads; i++) {
		set_thread(i);
		rc = spdk_thread_exit(g_ut_threads[i].thread);
		thread = g_ut_threads[i].thread;
		rc = spdk_thread_exit(thread);
		assert(rc == 0);
		spdk_thread_destroy(g_ut_threads[i].thread);
		while (!spdk_thread_is_exited(thread)) {
			spdk_thread_poll(thread, 0, 0);
		}
		spdk_thread_destroy(thread);
		g_ut_threads[i].thread = NULL;
	}

+3 −0
Original line number Diff line number Diff line
@@ -1181,6 +1181,9 @@ main(int argc, const char **argv)
	num_failures = CU_get_number_of_failures();

	spdk_thread_exit(g_thread);
	while (!spdk_thread_is_exited(g_thread)) {
		spdk_thread_poll(g_thread, 0, 0);
	}
	spdk_thread_destroy(g_thread);

	CU_cleanup_registry();
Loading