From 7d19e50a54914b777b31e873acc321e939ab4e43 Mon Sep 17 00:00:00 2001 From: Liu Xiaodong Date: Sat, 17 Oct 2020 09:00:48 -0400 Subject: [PATCH] reactor: extract reactor_post_process_lw_thread Change-Id: I2761db384f78529525b7f1eb3c9c959a7b885ede Signed-off-by: Liu Xiaodong Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4756 Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- lib/event/reactor.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/lib/event/reactor.c b/lib/event/reactor.c index 40fbf846e..208f9352d 100644 --- a/lib/event/reactor.c +++ b/lib/event/reactor.c @@ -309,6 +309,32 @@ _set_thread_name(const char *thread_name) static int _reactor_schedule_thread(struct spdk_thread *thread); static uint64_t g_rusage_period; +static bool +reactor_post_process_lw_thread(struct spdk_reactor *reactor, struct spdk_lw_thread *lw_thread) +{ + struct spdk_thread *thread = spdk_thread_get_from_ctx(lw_thread); + + if (spdk_unlikely(lw_thread->resched)) { + lw_thread->resched = false; + TAILQ_REMOVE(&reactor->threads, lw_thread, link); + assert(reactor->thread_count > 0); + reactor->thread_count--; + _reactor_schedule_thread(thread); + return true; + } + + if (spdk_unlikely(spdk_thread_is_exited(thread) && + spdk_thread_is_idle(thread))) { + TAILQ_REMOVE(&reactor->threads, lw_thread, link); + assert(reactor->thread_count > 0); + reactor->thread_count--; + spdk_thread_destroy(thread); + return true; + } + + return false; +} + static void _reactor_run(struct spdk_reactor *reactor) { @@ -331,23 +357,7 @@ _reactor_run(struct spdk_reactor *reactor) } reactor->tsc_last = now; - if (spdk_unlikely(lw_thread->resched)) { - lw_thread->resched = false; - TAILQ_REMOVE(&reactor->threads, lw_thread, link); - assert(reactor->thread_count > 0); - reactor->thread_count--; - _reactor_schedule_thread(thread); - continue; - } - - if (spdk_unlikely(spdk_thread_is_exited(thread) && - spdk_thread_is_idle(thread))) { - TAILQ_REMOVE(&reactor->threads, lw_thread, link); - assert(reactor->thread_count > 0); - reactor->thread_count--; - spdk_thread_destroy(thread); - continue; - } + reactor_post_process_lw_thread(reactor, lw_thread); } if (g_framework_context_switch_monitor_enabled) {