diff options
| author | Bernard Xiong <[email protected]> | 2019-04-04 13:37:01 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-04-04 13:37:01 +0800 |
| commit | 3d05ec698c3daaf6c21e739ecb46124dfc6db3c1 (patch) | |
| tree | cc747da88112d5d21bd5e2e02e9cd4b451dbb828 /src | |
| parent | b490052579e4229ae0c4c7ac0772fcc5d40195bc (diff) | |
| parent | 0366eb13acd55b5ba676e250366df440776b71d6 (diff) | |
Merge pull request #2541 from BernardXiong/fix_critical_smp
[Kernel] Fix the critical issue under smp
Diffstat (limited to 'src')
| -rw-r--r-- | src/scheduler.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/scheduler.c b/src/scheduler.c index 37b262d83b..be29d9a7e0 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -792,6 +792,12 @@ void rt_enter_critical(void) level = rt_hw_local_irq_disable(); current_thread = rt_cpu_self()->current_thread; + if (!current_thread) + { + rt_hw_local_irq_enable(level); + return ; + } + /* * the maximal number of nest is RT_UINT16_MAX, which is big * enough and does not check here @@ -842,6 +848,11 @@ void rt_exit_critical(void) level = rt_hw_local_irq_disable(); current_thread = rt_cpu_self()->current_thread; + if (!current_thread) + { + rt_hw_local_irq_enable(level); + return ; + } current_thread->scheduler_lock_nest --; @@ -873,14 +884,17 @@ void rt_exit_critical(void) level = rt_hw_interrupt_disable(); rt_scheduler_lock_nest --; - if (rt_scheduler_lock_nest <= 0) { rt_scheduler_lock_nest = 0; /* enable interrupt */ rt_hw_interrupt_enable(level); - rt_schedule(); + if (rt_current_thread) + { + /* if scheduler is started, do a schedule */ + rt_schedule(); + } } else { |
