This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 7cdf9a9627429f5b58932b2df24f4d4e6162daf7 Author: wangzhi16 <[email protected]> AuthorDate: Wed Nov 12 09:53:46 2025 +0800 include/spinlock: add is_in_critical_section. include/spinlock: add is_in_critical_section. Assisted-By: mimo-v2.6-pro Co-authored-by: ouyangxiangzhen <[email protected]> Signed-off-by: wangzhi16 <[email protected]> Signed-off-by: ouyangxiangzhen <[email protected]> --- include/nuttx/spinlock.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h index 89cc7f65c1a..e242f287bef 100644 --- a/include/nuttx/spinlock.h +++ b/include/nuttx/spinlock.h @@ -618,8 +618,18 @@ bool rspin_lock_is_recursive(FAR volatile rspinlock_t *lock) static inline_function bool rspin_lock_is_hold(FAR volatile rspinlock_t *lock) { - return RSPINLOCK_OWNER(atomic_read(&lock->val)) == - (uint32_t)this_cpu() + 1u; + bool ret; + + /* If this interface is not called while holding the rspinlock, the current + * task may be switched to another CPU during a context switch, + * leading to incorrect judgment. + */ + + irqstate_t flags = up_irq_save(); + ret = (RSPINLOCK_OWNER(atomic_read(&lock->val)) == + (uint32_t)this_cpu() + 1u); + up_irq_restore(flags); + return ret; } /****************************************************************************
