From b2315e98c44e91cfd26de2c8c1e2b1dbe47e06b5 Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Wed, 21 May 2025 19:33:04 +0300 Subject: [PATCH] sched/semaphore: Always free mutex holder at nxsem_post There is no need to check the holder structure "counts". There are cases where the counts may be greater than 1 when several tasks block on the mutex, but there is always just one holder, which must be freed. Signed-off-by: Jukka Laitinen --- sched/semaphore/sem_holder.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sched/semaphore/sem_holder.c b/sched/semaphore/sem_holder.c index cabe050992..3f9e610c2e 100644 --- a/sched/semaphore/sem_holder.c +++ b/sched/semaphore/sem_holder.c @@ -240,9 +240,11 @@ static int nxsem_freecount0holder(FAR struct semholder_s *pholder, { /* When no more counts are held, remove the holder from the list. The * count was decremented in nxsem_release_holder. + * + * Mutex is held only by one thread, so the holder is always freed. */ - if (pholder->counts <= 0) + if (pholder->counts <= 0 || NXSEM_IS_MUTEX(sem)) { nxsem_freeholder(sem, pholder); return 1; @@ -442,9 +444,11 @@ static int nxsem_restoreholderprio(FAR struct semholder_s *pholder, /* Release the holder if all counts have been given up * before reprioritizing causes a context switch. + * + * Mutex is held only by one thread, so the holder is always freed. */ - if (pholder->counts <= 0) + if (pholder->counts <= 0 || NXSEM_IS_MUTEX(sem)) { nxsem_freeholder(sem, pholder); }