From 4c13ed346c16bc919120a7ac5e9a7f93621e7f97 Mon Sep 17 00:00:00 2001 From: ryancw <1831931681@qq.com> Date: Wed, 20 Aug 2025 12:07:25 +0800 Subject: [PATCH] =?UTF-8?q?[kernel]=20rt=5Fscheduler=5Flock=5Fnest?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=8E=9F=E5=AD=90=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scheduler_up.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/scheduler_up.c b/src/scheduler_up.c index c4c6ec66ec2..5dedb33d36d 100644 --- a/src/scheduler_up.c +++ b/src/scheduler_up.c @@ -31,6 +31,7 @@ * 2023-03-27 rose_man Split into scheduler upc and scheduler_mp.c * 2023-10-17 ChuShicheng Modify the timing of clearing RT_THREAD_STAT_YIELD flag bits * 2025-08-04 Pillar Add rt_scheduler_critical_switch_flag + * 2025-08-20 RyanCW rt_scheduler_lock_nest use atomic operations */ #define __RT_IPC_SOURCE__ @@ -49,7 +50,7 @@ rt_uint8_t rt_thread_ready_table[32]; #endif /* RT_THREAD_PRIORITY_MAX > 32 */ extern volatile rt_atomic_t rt_interrupt_nest; -static rt_int16_t rt_scheduler_lock_nest; +static rt_atomic_t rt_scheduler_lock_nest; rt_uint8_t rt_current_priority; static rt_int8_t rt_scheduler_critical_switch_flag; @@ -649,22 +650,9 @@ RTM_EXPORT(rt_exit_critical_safe); */ rt_base_t rt_enter_critical(void) { - rt_base_t level; rt_base_t critical_level; - /* disable interrupt */ - level = rt_hw_interrupt_disable(); - - /* - * the maximal number of nest is RT_UINT16_MAX, which is big - * enough and does not check here - */ - rt_scheduler_lock_nest ++; - critical_level = rt_scheduler_lock_nest; - - /* enable interrupt */ - rt_hw_interrupt_enable(level); - + critical_level = rt_atomic_add(&rt_scheduler_lock_nest, 1) + 1; return critical_level; } RTM_EXPORT(rt_enter_critical); @@ -722,7 +710,7 @@ RTM_EXPORT(rt_exit_critical); */ rt_uint16_t rt_critical_level(void) { - return rt_scheduler_lock_nest; + return (rt_uint16_t)rt_atomic_load(&rt_scheduler_lock_nest); } RTM_EXPORT(rt_critical_level);