mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-02-21 22:15:34 +08:00
Merge pull request #2541 from BernardXiong/fix_critical_smp
[Kernel] Fix the critical issue under smp
This commit is contained in:
commit
3d05ec698c
@ -792,6 +792,12 @@ void rt_enter_critical(void)
|
|||||||
level = rt_hw_local_irq_disable();
|
level = rt_hw_local_irq_disable();
|
||||||
|
|
||||||
current_thread = rt_cpu_self()->current_thread;
|
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
|
* the maximal number of nest is RT_UINT16_MAX, which is big
|
||||||
* enough and does not check here
|
* enough and does not check here
|
||||||
@ -842,6 +848,11 @@ void rt_exit_critical(void)
|
|||||||
level = rt_hw_local_irq_disable();
|
level = rt_hw_local_irq_disable();
|
||||||
|
|
||||||
current_thread = rt_cpu_self()->current_thread;
|
current_thread = rt_cpu_self()->current_thread;
|
||||||
|
if (!current_thread)
|
||||||
|
{
|
||||||
|
rt_hw_local_irq_enable(level);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
current_thread->scheduler_lock_nest --;
|
current_thread->scheduler_lock_nest --;
|
||||||
|
|
||||||
@ -873,14 +884,17 @@ void rt_exit_critical(void)
|
|||||||
level = rt_hw_interrupt_disable();
|
level = rt_hw_interrupt_disable();
|
||||||
|
|
||||||
rt_scheduler_lock_nest --;
|
rt_scheduler_lock_nest --;
|
||||||
|
|
||||||
if (rt_scheduler_lock_nest <= 0)
|
if (rt_scheduler_lock_nest <= 0)
|
||||||
{
|
{
|
||||||
rt_scheduler_lock_nest = 0;
|
rt_scheduler_lock_nest = 0;
|
||||||
/* enable interrupt */
|
/* enable interrupt */
|
||||||
rt_hw_interrupt_enable(level);
|
rt_hw_interrupt_enable(level);
|
||||||
|
|
||||||
rt_schedule();
|
if (rt_current_thread)
|
||||||
|
{
|
||||||
|
/* if scheduler is started, do a schedule */
|
||||||
|
rt_schedule();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user