|
33 | 33 | #include <rtthread.h> |
34 | 34 | #include <rthw.h> |
35 | 35 |
|
36 | | -#ifdef RT_USING_SMP |
37 | | -rt_hw_spinlock_t _rt_critical_lock; |
38 | | -#endif /*RT_USING_SMP*/ |
39 | | - |
40 | 36 | rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX]; |
41 | 37 | rt_uint32_t rt_thread_ready_priority_group; |
42 | 38 | #if RT_THREAD_PRIORITY_MAX > 32 |
@@ -851,20 +847,23 @@ void rt_enter_critical(void) |
851 | 847 | if (!current_thread) |
852 | 848 | { |
853 | 849 | rt_hw_local_irq_enable(level); |
854 | | - return ; |
| 850 | + return; |
855 | 851 | } |
856 | 852 |
|
857 | 853 | /* |
858 | 854 | * the maximal number of nest is RT_UINT16_MAX, which is big |
859 | 855 | * enough and does not check here |
860 | 856 | */ |
861 | 857 |
|
862 | | - /* lock scheduler for all cpus */ |
863 | | - if (current_thread->critical_lock_nest == 0) |
864 | 858 | { |
865 | | - rt_hw_spin_lock(&_rt_critical_lock); |
| 859 | + register rt_uint16_t lock_nest = current_thread->cpus_lock_nest; |
| 860 | + current_thread->cpus_lock_nest++; |
| 861 | + if (lock_nest == 0) |
| 862 | + { |
| 863 | + current_thread->scheduler_lock_nest ++; |
| 864 | + rt_hw_spin_lock(&_cpus_lock); |
| 865 | + } |
866 | 866 | } |
867 | | - |
868 | 867 | /* critical for local cpu */ |
869 | 868 | current_thread->critical_lock_nest ++; |
870 | 869 |
|
@@ -910,16 +909,18 @@ void rt_exit_critical(void) |
910 | 909 | if (!current_thread) |
911 | 910 | { |
912 | 911 | rt_hw_local_irq_enable(level); |
913 | | - return ; |
| 912 | + return; |
914 | 913 | } |
915 | 914 |
|
916 | 915 | current_thread->scheduler_lock_nest --; |
917 | 916 |
|
918 | 917 | current_thread->critical_lock_nest --; |
919 | 918 |
|
920 | | - if (current_thread->critical_lock_nest == 0) |
| 919 | + current_thread->cpus_lock_nest--; |
| 920 | + if (current_thread->cpus_lock_nest == 0) |
921 | 921 | { |
922 | | - rt_hw_spin_unlock(&_rt_critical_lock); |
| 922 | + current_thread->scheduler_lock_nest --; |
| 923 | + rt_hw_spin_unlock(&_cpus_lock); |
923 | 924 | } |
924 | 925 |
|
925 | 926 | if (current_thread->scheduler_lock_nest <= 0) |
|
0 commit comments