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 <jukkax@ssrc.tii.ae>
This commit is contained in:
Jukka Laitinen 2024-09-27 09:43:47 +03:00 committed by Xiang Xiao
parent 429252152a
commit 07d5bc2c50
1 changed files with 3 additions and 2 deletions

View File

@ -100,8 +100,9 @@ int nxsem_tickwait(FAR sem_t *sem, uint32_t delay)
if (delay == 0) if (delay == 0)
{ {
/* Return the errno from nxsem_trywait() */ /* Timed out already before waiting */
ret = -ETIMEDOUT;
goto out; goto out;
} }
@ -149,7 +150,7 @@ out:
int nxsem_tickwait_uninterruptible(FAR sem_t *sem, uint32_t delay) 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; int ret;
for (; ; ) for (; ; )