Skip to content

Commit

Permalink
sched/semaphore/sem_tickwait.c: Fix nxsem_tickwait_uninterruptible en…
Browse files Browse the repository at this point in the history
…d 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 <[email protected]>
  • Loading branch information
jlaitine authored and xiaoxiang781216 committed Sep 30, 2024
1 parent 4292521 commit 07d5bc2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sched/semaphore/sem_tickwait.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -149,7 +150,7 @@ int nxsem_tickwait(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;

for (; ; )
Expand Down

0 comments on commit 07d5bc2

Please sign in to comment.