31
31
* 2023-03-27 rose_man Split into scheduler upc and scheduler_mp.c
32
32
* 2023-10-17 ChuShicheng Modify the timing of clearing RT_THREAD_STAT_YIELD flag bits
33
33
* 2025-08-04 Pillar Add rt_scheduler_critical_switch_flag
34
+ * 2025-08-20 RyanCW rt_scheduler_lock_nest use atomic operations
34
35
*/
35
36
36
37
#define __RT_IPC_SOURCE__
@@ -49,7 +50,7 @@ rt_uint8_t rt_thread_ready_table[32];
49
50
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
50
51
51
52
extern volatile rt_atomic_t rt_interrupt_nest ;
52
- static rt_int16_t rt_scheduler_lock_nest ;
53
+ static rt_atomic_t rt_scheduler_lock_nest ;
53
54
rt_uint8_t rt_current_priority ;
54
55
55
56
static rt_int8_t rt_scheduler_critical_switch_flag ;
@@ -649,22 +650,9 @@ RTM_EXPORT(rt_exit_critical_safe);
649
650
*/
650
651
rt_base_t rt_enter_critical (void )
651
652
{
652
- rt_base_t level ;
653
653
rt_base_t critical_level ;
654
654
655
- /* disable interrupt */
656
- level = rt_hw_interrupt_disable ();
657
-
658
- /*
659
- * the maximal number of nest is RT_UINT16_MAX, which is big
660
- * enough and does not check here
661
- */
662
- rt_scheduler_lock_nest ++ ;
663
- critical_level = rt_scheduler_lock_nest ;
664
-
665
- /* enable interrupt */
666
- rt_hw_interrupt_enable (level );
667
-
655
+ critical_level = rt_atomic_add (& rt_scheduler_lock_nest , 1 ) + 1 ;
668
656
return critical_level ;
669
657
}
670
658
RTM_EXPORT (rt_enter_critical );
@@ -722,7 +710,7 @@ RTM_EXPORT(rt_exit_critical);
722
710
*/
723
711
rt_uint16_t rt_critical_level (void )
724
712
{
725
- return rt_scheduler_lock_nest ;
713
+ return ( rt_uint16_t ) rt_atomic_load ( & rt_scheduler_lock_nest ) ;
726
714
}
727
715
RTM_EXPORT (rt_critical_level );
728
716
0 commit comments