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 2ebb12f1d6eb0740bc734834803f85262bc57ffc
Author: ouyangxiangzhen <[email protected]>
AuthorDate: Tue Nov 24 09:43:11 2026 +0800

    spinlock: align rspin_lock_is_hold with the downstream form
    
    The is_hold helper used the raw up_irq_save()/up_irq_restore() window
    and read the owner only through the atomic value.  Align with the
    downstream implementation: use the instrumented irq_save()/irq_restore()
    window on SMP, and on !CONFIG_SPINLOCK builds report the recursive count
    from local_val (no atomic read is needed because interrupts are not
    disabled and the lock is task-local there).
    
    This is a series-original fix: it completes the alignment of the
    merge-stream helper with the reference implementation.
    
    Assisted-By: mimo-v2.6-pro
    Signed-off-by: ouyangxiangzhen <[email protected]>
---
 include/nuttx/spinlock.h | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/include/nuttx/spinlock.h b/include/nuttx/spinlock.h
index 7419ae5c2b9..475ca3bf5b3 100644
--- a/include/nuttx/spinlock.h
+++ b/include/nuttx/spinlock.h
@@ -618,10 +618,15 @@ bool rspin_lock_is_hold(FAR volatile rspinlock_t *lock)
    * 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);
+#ifdef CONFIG_SPINLOCK
+  irqstate_t flags = irq_save();
+  ret = RSPINLOCK_OWNER(atomic_read(&lock->val)) ==
+                        (uint32_t)this_cpu() + 1u;
+  irq_restore(flags);
+#else
+  ret = RSPINLOCK_COUNT(lock->local_val) > 0u;
+#endif
+
   return ret;
 }
 

Reply via email to