2 #include "pthread_impl.h"
4 static void cleanup(void *p
)
9 int sem_timedwait(sem_t
*restrict sem
, const struct timespec
*restrict at
)
13 if (!sem_trywait(sem
)) return 0;
16 while (spins
-- && sem
->__val
[0] <= 0 && !sem
->__val
[1]) a_spin();
18 while (sem_trywait(sem
)) {
21 a_cas(sem
->__val
, 0, -1);
22 pthread_cleanup_push(cleanup
, (void *)(sem
->__val
+1));
23 r
= __timedwait_cp(sem
->__val
, -1, CLOCK_REALTIME
, at
, sem
->__val
[2]);
24 pthread_cleanup_pop(1);