2 #include "pthread_impl.h"
4 static void cleanup(void *p)
9 int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at)
11 if (!sem_trywait(sem)) return 0;
14 while (spins-- && sem->__val[0] <= 0 && !sem->__val[1]) a_spin();
16 while (sem_trywait(sem)) {
19 a_cas(sem->__val, 0, -1);
20 r = __timedwait(sem->__val, -1, CLOCK_REALTIME, at, cleanup, sem->__val+1, sem->__val[2]);