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


The following commit(s) were added to refs/heads/master by this push:
     new 8f62ee13899 sched/semaphore: Clear mutex blocking bit after timeout
8f62ee13899 is described below

commit 8f62ee13899d21378a7c83b5d83d736153f2e4c0
Author: Martin Krasula <[email protected]>
AuthorDate: Thu Jul 16 14:59:43 2026 +0200

    sched/semaphore: Clear mutex blocking bit after timeout
    
    Clear NXSEM_MBLOCKING_BIT in nxsem_wait_irq() when a mutex waiter is
    removed and the wait queue becomes empty.
    
    Signed-off-by: Martin Krasula <[email protected]>
---
 sched/semaphore/sem_waitirq.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/sched/semaphore/sem_waitirq.c b/sched/semaphore/sem_waitirq.c
index 5f73031b201..e0eec5e42e0 100644
--- a/sched/semaphore/sem_waitirq.c
+++ b/sched/semaphore/sem_waitirq.c
@@ -96,14 +96,19 @@ void nxsem_wait_irq(FAR struct tcb_s *wtcb, int errcode)
 
       dq_rem((FAR dq_entry_t *)wtcb, SEM_WAITLIST(sem));
 
-      /* This restores the value to what it was before the previous sem_wait.
-       * This caused the thread to be blocked in the first place.
-       *
-       * For mutexes, the holder is updated by the thread itself
-       * when it exits nxsem_wait
+      /* Restore the semaphore state changed by the previous sem_wait().
+       * For mutexes, the holder TID remains unchanged, but the blocking bit
+       * must be cleared when the timed-out task was the last waiter.
        */
 
-      if (!mutex)
+      if (mutex)
+        {
+          if (dq_empty(SEM_WAITLIST(sem)))
+            {
+              atomic_fetch_and(NXSEM_MHOLDER(sem), ~NXSEM_MBLOCKING_BIT);
+            }
+        }
+      else
         {
           atomic_fetch_add(NXSEM_COUNT(sem), 1);
         }

Reply via email to