Skip to content

[kernel]Fixed issue that could all timers stop #5637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ static void _timer_init(rt_timer_t timer,
*
* @param timer_list is the array of time list
*
* @return the next timer's ticks
* @param timeout_tick is the next timer's ticks
*
* @return Return the operation status. If the return value is RT_EOK, the function is successfully executed.
* If the return value is any other values, it means this operation failed.
*/
static rt_tick_t _timer_list_next_timeout(rt_list_t timer_list[])
static rt_err_t _timer_list_next_timeout(rt_list_t timer_list[], rt_tick_t *timeout_tick)
{
struct rt_timer *timer;
register rt_base_t level;
rt_tick_t timeout_tick = RT_TICK_MAX;

/* disable interrupt */
level = rt_hw_interrupt_disable();
Expand All @@ -163,13 +165,18 @@ static rt_tick_t _timer_list_next_timeout(rt_list_t timer_list[])
{
timer = rt_list_entry(timer_list[RT_TIMER_SKIP_LIST_LEVEL - 1].next,
struct rt_timer, row[RT_TIMER_SKIP_LIST_LEVEL - 1]);
timeout_tick = timer->timeout_tick;
*timeout_tick = timer->timeout_tick;

/* enable interrupt */
rt_hw_interrupt_enable(level);

return RT_EOK;
}

/* enable interrupt */
rt_hw_interrupt_enable(level);

return timeout_tick;
return -RT_ERROR;
}

/**
Expand Down Expand Up @@ -565,6 +572,7 @@ rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
break;

case RT_TIMER_CTRL_SET_TIME:
RT_ASSERT((*(rt_tick_t *)arg) < RT_TICK_MAX / 2);
timer->init_tick = *(rt_tick_t *)arg;
break;

Expand Down Expand Up @@ -682,7 +690,9 @@ void rt_timer_check(void)
*/
rt_tick_t rt_timer_next_timeout_tick(void)
{
return _timer_list_next_timeout(_timer_list);
rt_tick_t next_timeout = RT_TICK_MAX;
_timer_list_next_timeout(_timer_list, &next_timeout);
return next_timeout;
}

#ifdef RT_USING_TIMER_SOFT
Expand Down Expand Up @@ -776,8 +786,7 @@ static void _timer_thread_entry(void *parameter)
while (1)
{
/* get the next timeout tick */
next_timeout = _timer_list_next_timeout(_soft_timer_list);
if (next_timeout == RT_TICK_MAX)
if (_timer_list_next_timeout(_soft_timer_list, &next_timeout) != RT_EOK)
{
/* no software timer exist, suspend self. */
rt_thread_suspend(rt_thread_self());
Expand Down