3 #include "pthread_impl.h"
5 static void cleanup(void *p)
10 int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at)
14 if (!sem_trywait(sem)) return 0;
17 while (spins-- && !(sem->__val[0] & SEM_VALUE_MAX) && !sem->__val[1])
20 while (sem_trywait(sem)) {
21 int r, priv = sem->__val[2];
23 a_cas(sem->__val, 0, 0x80000000);
24 pthread_cleanup_push(cleanup, (void *)(sem->__val+1));
25 r = __timedwait_cp(sem->__val, 0x80000000, CLOCK_REALTIME, at, priv);
26 pthread_cleanup_pop(1);