Merge pull request #4751 from mysterywolf/protect

[kernel]对rt_tick_increase临界区进行保护
This commit is contained in:
Bernard Xiong 2021-06-01 21:03:19 +08:00 committed by GitHub
commit aa13a78b3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

@ -62,6 +62,9 @@ void rt_tick_set(rt_tick_t tick)
void rt_tick_increase(void) void rt_tick_increase(void)
{ {
struct rt_thread *thread; struct rt_thread *thread;
rt_base_t level;
level = rt_hw_interrupt_disable();
/* increase the global tick */ /* increase the global tick */
#ifdef RT_USING_SMP #ifdef RT_USING_SMP
@ -76,17 +79,17 @@ void rt_tick_increase(void)
-- thread->remaining_tick; -- thread->remaining_tick;
if (thread->remaining_tick == 0) if (thread->remaining_tick == 0)
{ {
rt_base_t level;
/* change to initialized tick */ /* change to initialized tick */
thread->remaining_tick = thread->init_tick; thread->remaining_tick = thread->init_tick;
level = rt_hw_interrupt_disable();
thread->stat |= RT_THREAD_STAT_YIELD; thread->stat |= RT_THREAD_STAT_YIELD;
rt_hw_interrupt_enable(level);
rt_hw_interrupt_enable(level);
rt_schedule(); rt_schedule();
} }
else
{
rt_hw_interrupt_enable(level);
}
/* check timer */ /* check timer */
rt_timer_check(); rt_timer_check();