This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit ba06ea6fd7a5161b367bcefae0168530c4068f4f
Author: ouyangxiangzhen <ouyangxiangz...@xiaomi.com>
AuthorDate: Tue Mar 18 21:24:51 2025 +0800

    sched/wdog: Simplify nxsched_timer_process.
    
    This commit simplified `nxsched_timer_process` implementation and
    improve its readability.
    
    Signed-off-by: ouyangxiangzhen <ouyangxiangz...@xiaomi.com>
---
 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);
+
+  /* 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 rettime;
+  return next_time;
 }
 
 /****************************************************************************

Reply via email to