From ba06ea6fd7a5161b367bcefae0168530c4068f4f Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Tue, 18 Mar 2025 21:24:51 +0800 Subject: [PATCH] sched/wdog: Simplify nxsched_timer_process. This commit simplified `nxsched_timer_process` implementation and improve its readability. Signed-off-by: ouyangxiangzhen --- sched/sched/sched_timerexpiration.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/sched/sched/sched_timerexpiration.c b/sched/sched/sched_timerexpiration.c index a139e3c9b7..1d268877cd 100644 --- a/sched/sched/sched_timerexpiration.c +++ b/sched/sched/sched_timerexpiration.c @@ -348,8 +348,9 @@ static clock_t nxsched_process_scheduler(clock_t ticks, clock_t elapsed, static clock_t nxsched_timer_process(clock_t ticks, clock_t elapsed, bool noswitches) { - clock_t rettime = 0; - clock_t tmp; + clock_t sched_next_time; + clock_t wdog_next_time; + clock_t next_time; #ifdef CONFIG_CLOCK_TIMEKEEPING /* Process wall time */ @@ -361,21 +362,21 @@ static clock_t nxsched_timer_process(clock_t ticks, clock_t elapsed, * active task. */ - tmp = nxsched_process_scheduler(ticks, elapsed, noswitches); - if (tmp > 0) - { - rettime = tmp; - } + sched_next_time = nxsched_process_scheduler(ticks, elapsed, noswitches); /* Process watchdogs */ - tmp = wd_timer(ticks, noswitches); - if (tmp > 0 && (rettime == 0 || tmp < rettime)) - { - rettime = tmp; - } + wdog_next_time = wd_timer(ticks, noswitches); - return rettime; + /* If sched_next_time or wdog_next_time is 0, + * then subtracting 1 overflows to the maximum value, + * which is never selected. + */ + + next_time = MIN(sched_next_time - 1, wdog_next_time - 1); + next_time += 1; + + return next_time; } /****************************************************************************