summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorryancw <[email protected]>2025-08-20 12:07:25 +0800
committerR b b666 <[email protected]>2025-08-28 11:33:15 +0800
commitdf70e4b9bc2198227cf48544eed6e7c45c055169 (patch)
treef6c3a2252e2e7d4e33f548766f23bb784ff20a43
parent98cb15a3ef2cddfaa69272778d9a7e184834d6d0 (diff)
[kernel] rt_scheduler_lock_nest使用原子操作
-rw-r--r--src/scheduler_up.c20
1 files changed, 4 insertions, 16 deletions
diff --git a/src/scheduler_up.c b/src/scheduler_up.c
index c4c6ec66ec..5dedb33d36 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);