From 07d5bc2c50bf9906c950adbbf53d219a32049315 Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Fri, 27 Sep 2024 09:43:47 +0300 Subject: [PATCH] sched/semaphore/sem_tickwait.c: Fix nxsem_tickwait_uninterruptible end condition nxsem_tickwait correctly sleeps more than 1 tick. But nxsem_tickwait_uninterruptible may wake up to a signal (with -EINTR), in which case the tick + 1 must also be taken into account. Otherwise the nxsem_tickwait_uninterruptible may wake up 1 tick too early. Also fix the nxsem_tickwait to return with -ETIMEDOUT if called with delay 0. This is similar to e.g. posix sem_timedwait. Signed-off-by: Jukka Laitinen --- sched/semaphore/sem_tickwait.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sched/semaphore/sem_tickwait.c b/sched/semaphore/sem_tickwait.c index c6d4217395..9f219bc571 100644 --- a/sched/semaphore/sem_tickwait.c +++ b/sched/semaphore/sem_tickwait.c @@ -100,8 +100,9 @@ int nxsem_tickwait(FAR sem_t *sem, uint32_t delay) if (delay == 0) { - /* Return the errno from nxsem_trywait() */ + /* Timed out already before waiting */ + ret = -ETIMEDOUT; goto out; } @@ -149,7 +150,7 @@ out: int nxsem_tickwait_uninterruptible(FAR sem_t *sem, uint32_t delay) { - clock_t end = clock_systime_ticks() + delay; + clock_t end = clock_systime_ticks() + delay + 1; int ret; for (; ; )