diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/thread/sem_timedwait.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/thread/sem_timedwait.c b/src/thread/sem_timedwait.c index bfcb6dcd..df5f3a6c 100644 --- a/src/thread/sem_timedwait.c +++ b/src/thread/sem_timedwait.c @@ -8,6 +8,11 @@ static void cleanup(void *p) int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at) { + if (!sem_trywait(sem)) return 0; + + int spins = 100; + while (spins-- && sem->__val[0] <= 0) a_spin(); + while (sem_trywait(sem)) { int r; a_inc(sem->__val+1); |