From d4826d874e805625decca3c59984cb3638b4d1ae Mon Sep 17 00:00:00 2001 From: Lixin Guo Date: Tue, 7 Dec 2021 16:05:43 +0800 Subject: [PATCH] kernel: work: remove unused if statement Condition of work == NULL is checked before, so there is no need to check it again. Signed-off-by: Lixin Guo --- kernel/work.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/kernel/work.c b/kernel/work.c index ebd3b3f8b14..0c0ac10ceb6 100644 --- a/kernel/work.c +++ b/kernel/work.c @@ -586,6 +586,7 @@ static void work_queue_main(void *workq_ptr, void *p2, void *p3) struct k_work *work = NULL; k_work_handler_t handler = NULL; k_spinlock_key_t key = k_spin_lock(&lock); + bool yield; /* Check for and prepare any new work. */ node = sys_slist_get(&queue->pending); @@ -644,34 +645,30 @@ static void work_queue_main(void *workq_ptr, void *p2, void *p3) k_spin_unlock(&lock, key); - if (work != NULL) { - bool yield; + __ASSERT_NO_MSG(handler != NULL); + handler(work); - __ASSERT_NO_MSG(handler != NULL); - handler(work); + /* Mark the work item as no longer running and deal + * with any cancellation issued while it was running. + * Clear the BUSY flag and optionally yield to prevent + * starving other threads. + */ + key = k_spin_lock(&lock); - /* Mark the work item as no longer running and deal - * with any cancellation issued while it was running. - * Clear the BUSY flag and optionally yield to prevent - * starving other threads. - */ - key = k_spin_lock(&lock); + flag_clear(&work->flags, K_WORK_RUNNING_BIT); + if (flag_test(&work->flags, K_WORK_CANCELING_BIT)) { + finalize_cancel_locked(work); + } - flag_clear(&work->flags, K_WORK_RUNNING_BIT); - if (flag_test(&work->flags, K_WORK_CANCELING_BIT)) { - finalize_cancel_locked(work); - } + flag_clear(&queue->flags, K_WORK_QUEUE_BUSY_BIT); + yield = !flag_test(&queue->flags, K_WORK_QUEUE_NO_YIELD_BIT); + k_spin_unlock(&lock, key); - flag_clear(&queue->flags, K_WORK_QUEUE_BUSY_BIT); - yield = !flag_test(&queue->flags, K_WORK_QUEUE_NO_YIELD_BIT); - k_spin_unlock(&lock, key); - - /* Optionally yield to prevent the work queue from - * starving other threads. - */ - if (yield) { - k_yield(); - } + /* Optionally yield to prevent the work queue from + * starving other threads. + */ + if (yield) { + k_yield(); } } }