This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit a03b88f0f857012e7df7cb611daa11738128d754
Author: Marco Casaroli <[email protected]>
AuthorDate: Wed Nov 4 10:47:50 2026 +0100

    libs/libc/pthread: Return EBUSY from trylock of a spinlock the caller holds.
    
    pthread_spin_trylock() returned 0 when the caller already held the
    lock, but the lock is not recursive: the first pthread_spin_unlock()
    releases it.  POSIX specifies EBUSY when a thread currently holds the
    lock.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 libs/libc/pthread/pthread_spinlock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libs/libc/pthread/pthread_spinlock.c 
b/libs/libc/pthread/pthread_spinlock.c
index 7211e1d2ca8..627086a3327 100644
--- a/libs/libc/pthread/pthread_spinlock.c
+++ b/libs/libc/pthread/pthread_spinlock.c
@@ -216,7 +216,7 @@ int pthread_spin_lock(pthread_spinlock_t *lock)
  *   of the following errno values are returned:
  *
  *   EINVAL - 'lock' does not refer to a valid spinlock object
- *   EBUSY  - The spinlock is held by another thread
+ *   EBUSY  - The spinlock is held by a thread, also by the caller
  *
  ****************************************************************************/
 
@@ -233,7 +233,7 @@ int pthread_spin_trylock(pthread_spinlock_t *lock)
     }
   else if (lock->sp_holder == me)
     {
-      ret = OK;
+      ret = EBUSY;
     }
   else
     {

Reply via email to