[kernel] rt_scheduler_lock_nest使用原子操作
Some checks failed
AutoTestCI / components/cpp11 (push) Has been cancelled
AutoTestCI / kernel/atomic (push) Has been cancelled
AutoTestCI / kernel/atomic/riscv64 (push) Has been cancelled
AutoTestCI / kernel/atomic_c11 (push) Has been cancelled
AutoTestCI / kernel/atomic_c11/riscv64 (push) Has been cancelled
AutoTestCI / kernel/device (push) Has been cancelled
AutoTestCI / kernel/ipc (push) Has been cancelled
AutoTestCI / kernel/irq (push) Has been cancelled
AutoTestCI / kernel/mem (push) Has been cancelled
AutoTestCI / kernel/mem/riscv64 (push) Has been cancelled
AutoTestCI / kernel/thread (push) Has been cancelled
AutoTestCI / kernel/timer (push) Has been cancelled
AutoTestCI / rtsmart/aarch64 (push) Has been cancelled
AutoTestCI / rtsmart/arm (push) Has been cancelled
AutoTestCI / rtsmart/riscv64 (push) Has been cancelled
AutoTestCI / components/utest (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
doc_doxygen / doxygen_doc generate (push) Has been cancelled
doc_doxygen / deploy (push) Has been cancelled

This commit is contained in:
ryancw
2025-08-20 12:07:25 +08:00
committed by R b b666
parent 98cb15a3ef
commit df70e4b9bc

View File

@@ -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);