summaryrefslogtreecommitdiff
path: root/src/timer.c
diff options
context:
space:
mode:
authorWillianChan <[email protected]>2021-08-31 10:39:44 +0800
committerWillianChan <[email protected]>2021-08-31 17:14:30 +0800
commit75b65ebcf2d2261bcd5cf762cc8aa8452e78b8d1 (patch)
treeebc987a6ea73d634ed8727f6b0484518d6047eed /src/timer.c
parent553b57e3a901519e1fec8e667fb594991d681503 (diff)
[fix][kernel][timer]fixed timer ASSERT exception due to multithreaded scheduling
Signed-off-by: WillianChan <[email protected]>
Diffstat (limited to 'src/timer.c')
-rw-r--r--src/timer.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/timer.c b/src/timer.c
index da52a02fc8..25ba175306 100644
--- a/src/timer.c
+++ b/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);