[fix][kernel][timer]fixed timer ASSERT exception due to multithreaded scheduling
Signed-off-by: WillianChan <chentingwei@rt-thread.com>
This commit is contained in:
parent
553b57e3a9
commit
75b65ebcf2
16
src/timer.c
16
src/timer.c
|
@ -367,6 +367,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
|||
unsigned int row_lvl;
|
||||
rt_list_t *timer_list;
|
||||
register rt_base_t level;
|
||||
register rt_bool_t need_schedule;
|
||||
rt_list_t *row_head[RT_TIMER_SKIP_LIST_LEVEL];
|
||||
unsigned int tst_nr;
|
||||
static unsigned int random_nr;
|
||||
|
@ -375,6 +376,8 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
|||
RT_ASSERT(timer != RT_NULL);
|
||||
RT_ASSERT(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer);
|
||||
|
||||
need_schedule = RT_FALSE;
|
||||
|
||||
/* stop timer firstly */
|
||||
level = rt_hw_interrupt_disable();
|
||||
/* remove timer from list */
|
||||
|
@ -457,9 +460,6 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
|||
|
||||
timer->parent.flag |= RT_TIMER_FLAG_ACTIVATED;
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
#ifdef RT_USING_TIMER_SOFT
|
||||
if (timer->parent.flag & RT_TIMER_FLAG_SOFT_TIMER)
|
||||
{
|
||||
|
@ -469,11 +469,19 @@ rt_err_t rt_timer_start(rt_timer_t timer)
|
|||
{
|
||||
/* resume timer thread to check soft timer */
|
||||
rt_thread_resume(&_timer_thread);
|
||||
rt_schedule();
|
||||
need_schedule = RT_TRUE;
|
||||
}
|
||||
}
|
||||
#endif /* RT_USING_TIMER_SOFT */
|
||||
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
if (need_schedule)
|
||||
{
|
||||
rt_schedule();
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
RTM_EXPORT(rt_timer_start);
|
||||
|
|
Loading…
Reference in New Issue