Skip to content

Commit 3d8c27b

Browse files
authored
[ktime] quality: remove recursion on hrtimer (#9110)
[ktime] feat: remove recursion on hrtimer Replace recursive algorithm with a loop in hrtimer when determining next timeout event and setup hr timer. Signed-off-by: Shell <[email protected]>
1 parent b79d501 commit 3d8c27b

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Diff for: components/drivers/ktime/src/hrtimer.c

+15-9
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,26 @@ static void _set_next_timeout_locked(void)
146146
{
147147
rt_ktime_hrtimer_t timer;
148148
rt_ubase_t next_timeout_hrtimer_cnt;
149+
rt_bool_t find_next;
149150

150-
if ((timer = _first_hrtimer()) != RT_NULL)
151+
do
151152
{
152-
next_timeout_hrtimer_cnt = _cnt_convert(timer->timeout_cnt);
153-
if (next_timeout_hrtimer_cnt > 0)
153+
find_next = RT_FALSE;
154+
if ((timer = _first_hrtimer()) != RT_NULL)
154155
{
155-
rt_ktime_hrtimer_settimeout(next_timeout_hrtimer_cnt);
156-
}
157-
else
158-
{
159-
_hrtimer_process_locked();
160-
_set_next_timeout_locked();
156+
next_timeout_hrtimer_cnt = _cnt_convert(timer->timeout_cnt);
157+
if (next_timeout_hrtimer_cnt > 0)
158+
{
159+
rt_ktime_hrtimer_settimeout(next_timeout_hrtimer_cnt);
160+
}
161+
else
162+
{
163+
_hrtimer_process_locked();
164+
find_next = RT_TRUE;
165+
}
161166
}
162167
}
168+
while (find_next);
163169
}
164170

165171
void rt_ktime_hrtimer_process(void)

0 commit comments

Comments
 (0)