Files
musl/src/thread/sem_timedwait.c
Rich Felker bdd893377f fix sem_timedwait bug introduced in timedwait unification
this dec used to be performed by the cancellation handler, which was
called when popped.
2011-08-02 21:15:20 -04:00

24 lines
405 B
C

#include <semaphore.h>
#include "pthread_impl.h"
static void cleanup(void *p)
{
a_dec(p);
}
int sem_timedwait(sem_t *sem, const struct timespec *at)
{
while (sem_trywait(sem)) {
int r;
a_inc(sem->__val+1);
a_cas(sem->__val, 0, -1);
r = __timedwait(sem->__val, -1, CLOCK_REALTIME, at, cleanup, sem->__val+1, 0);
a_dec(sem->__val+1);
if (r) {
errno = r;
return -1;
}
}
return 0;
}