From c204c3d7862f575d710e64694debd020e46be99a Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Mon, 3 May 2021 09:30:50 +0900 Subject: [PATCH] thread: Change TAILQ_FOREACH_SAFE to TAILQ_FIRST() and _NEXT() for timed poller When we introduce red black tree for timed pollers, we will not use RB_FOREACH_SAFE() but cache the leftmost (smallest) node and iterate from it via RB_NEXT() instead. As another preparation, separate TAILQ_FOREACH_SAFE() into TAILQ_FIRST() and TAILQ_NEXT(). The next patch will cache the first element to thread and refer it first. Signed-off-by: Shuhei Matsumoto Change-Id: Ie03c387b5b3a055c668e7b439a5eb05ed77eaa81 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7718 Community-CI: Mellanox Build Bot Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Konrad Sztyber Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins --- lib/thread/thread.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/thread/thread.c b/lib/thread/thread.c index f6d1c6a35..b1cfe4835 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -746,17 +746,22 @@ thread_poll(struct spdk_thread *thread, uint32_t max_msgs, uint64_t now) } } - TAILQ_FOREACH_SAFE(poller, &thread->timed_pollers, tailq, tmp) { + poller = TAILQ_FIRST(&thread->timed_pollers); + while (poller != NULL) { int timer_rc = 0; if (now < poller->next_run_tick) { break; } + tmp = TAILQ_NEXT(poller, tailq); + timer_rc = thread_execute_timed_poller(thread, poller, now); if (timer_rc > rc) { rc = timer_rc; } + + poller = tmp; } return rc;