From 1e98e82051c1d24fbb12af05b3633410cba0d34f Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Mon, 10 Feb 2020 18:16:16 -0500 Subject: [PATCH] lib/thread: Stop new poller and reap unregistering poller after thread is marked as exited This is a preparation to support voluntary thread termination by calling spdk_thread_exit(). One of the subsequent patches will allow thread to exit only if all of its pollers are being unregistered. After the thread is marked as exited, only unregistering pollers will remain if the exited thread does not accept registering new poller. Hence in this patch, we change spdk_poller_register() to fail if the current thread is marked as exited first. Then, in subsequent patches, if we remove break from poller processing in spdk_thread_poll(), poller unregistration of the exited thread will complete, and we will be able to support voluntary thread termination easily by checking only the thread is exited and idle. Signed-off-by: Shuhei Matsumoto Change-Id: I5b843a07049ef01a5ff402eb521e294182ce2ae2 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/822 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Aleksey Marchuk --- lib/thread/thread.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 65ddd5bde..71c483154 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -512,10 +512,6 @@ spdk_thread_poll(struct spdk_thread *thread, uint32_t max_msgs, uint64_t now) active_pollers_head, tailq, tmp) { int poller_rc; - if (thread->exit) { - break; - } - if (poller->state == SPDK_POLLER_STATE_UNREGISTERED) { TAILQ_REMOVE(&thread->active_pollers, poller, tailq); free(poller); @@ -551,10 +547,6 @@ spdk_thread_poll(struct spdk_thread *thread, uint32_t max_msgs, uint64_t now) TAILQ_FOREACH_SAFE(poller, &thread->timed_pollers, tailq, tmp) { int timer_rc = 0; - if (thread->exit) { - break; - } - if (poller->state == SPDK_POLLER_STATE_UNREGISTERED) { TAILQ_REMOVE(&thread->timed_pollers, poller, tailq); free(poller); @@ -778,6 +770,11 @@ spdk_poller_register(spdk_poller_fn fn, return NULL; } + if (spdk_unlikely(thread->exit)) { + SPDK_ERRLOG("thread %s is marked as exited\n", thread->name); + return NULL; + } + poller = calloc(1, sizeof(*poller)); if (poller == NULL) { SPDK_ERRLOG("Poller memory allocation failed\n");