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

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

commit f0e26c75cc345b2a3df45d80f5ec726ee92cf4c6
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Wed Aug 26 16:10:59 2026 +0800

    sched/hrtimer: Convert hrtimer_process loop to while form
    
    Hoist the initial queue-head fetch before the loop and refresh it at
    the end of each iteration, replacing the for(;;)-with-break pattern
    with a plain while loop over the expiry condition.  No functional
    change.
    
    Assisted-By: mimo-v2.6-pro
    Signed-off-by: ouyangxiangzhen <[email protected]>
---
 sched/hrtimer/hrtimer.h | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/sched/hrtimer/hrtimer.h b/sched/hrtimer/hrtimer.h
index 18b1bb65505..4971a9f4605 100644
--- a/sched/hrtimer/hrtimer.h
+++ b/sched/hrtimer/hrtimer.h
@@ -666,12 +666,12 @@ static inline_function void hrtimer_wait(FAR hrtimer_t 
*timer)
 
 static inline_function void hrtimer_process(uint64_t now)
 {
-  FAR hrtimer_t  *hrtimer;
-  hrtimer_entry_t    func;
-  uint64_t        expired;
   uint64_t          delay;
   int                 cpu = this_cpu();
   irqstate_t        flags = hrtimer_lock();
+  FAR hrtimer_t  *hrtimer = hrtimer_get_first();
+  uint64_t        expired = hrtimer->expired;
+  hrtimer_entry_t    func = hrtimer->func;
 
 #ifdef CONFIG_SCHED_TICKLESS
   /* Invalidate the g_hrtimer_expected */
@@ -679,25 +679,14 @@ static inline_function void hrtimer_process(uint64_t now)
   g_hrtimer_expected = now;
 #endif
 
-  /* Acquire the lock and seize the ownership of the hrtimer queue. */
+  /* Acquire the lock and seize the ownership of the hrtimer queue.
+   * Then check if the timer has expired.
+   */
 
-  for (; ; )
+  while (HRTIMER_TIME_BEFORE_EQ(expired, now))
     {
-      /* Fetch the earliest active timer */
-
-      hrtimer = hrtimer_get_first();
-      expired = hrtimer->expired;
-
-      /* Check if the timer has expired */
-
-      if (!HRTIMER_TIME_BEFORE_EQ(expired, now))
-        {
-          break;
-        }
-
       /* Remove the expired timer from the timer queue */
 
-      func = hrtimer->func;
       hrtimer_remove(hrtimer);
 
       hrtimer_mark_running(hrtimer, cpu);
@@ -730,6 +719,12 @@ static inline_function void hrtimer_process(uint64_t now)
           hrtimer->func    = func;
           hrtimer_insert(hrtimer);
         }
+
+      /* Fetch the earliest active timer */
+
+      hrtimer = hrtimer_get_first();
+      expired = hrtimer->expired;
+      func    = hrtimer->func;
     }
 
   hrtimer_unmark_running(cpu);

Reply via email to