Browse Source

Merge pull request #4751 from mysterywolf/protect

[kernel]对rt_tick_increase临界区进行保护
Bernard Xiong 4 years ago
parent
commit
aa13a78b3f
1 changed files with 8 additions and 5 deletions
  1. 8 5
      src/clock.c

+ 8 - 5
src/clock.c

@@ -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();