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

example/nvmf: Fix the case when thread is terminated by communicating with other threads



As we have done for SPDK reactor, SPDK thread termination needs communication
among SPDK threads. So At application shutdown, create the while loop
until all threads are destroyed and in the loop, check each thread
is exited, and destroy the thread if exited or mark it as exiting
and retry checking after traversing other threads.

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


Community-CI: Mellanox Build Bot
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 avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent 90be351f
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -224,11 +224,17 @@ nvmf_reactor_run(void *arg)
	while (spdk_ring_dequeue(nvmf_reactor->threads, (void **)&lw_thread, 1)) {
		thread = spdk_thread_get_from_ctx(lw_thread);
		spdk_set_thread(thread);

		if (spdk_thread_is_exited(thread)) {
			spdk_thread_destroy(thread);
		} else {
			/* This thread is not exited yet, and may need to communicate with other threads
			 * to be exited. So mark it as exiting, and check again after traversing other threads.
			 */
			spdk_thread_exit(thread);
		while (!spdk_thread_is_exited(thread)) {
			spdk_thread_poll(thread, 0, 0);
			spdk_ring_enqueue(nvmf_reactor->threads, (void **)&lw_thread, 1, NULL);
		}
		spdk_thread_destroy(thread);
	}

	return 0;