6 #include "pthread_impl.h"
8 int __timedwait_cp(volatile int *addr, int val,
9 clockid_t clk, const struct timespec *at, int priv)
12 struct timespec to, *top=0;
14 if (priv) priv = FUTEX_PRIVATE;
17 if (at->tv_nsec >= 1000000000UL) return EINVAL;
18 if (__clock_gettime(clk, &to)) return EINVAL;
19 to.tv_sec = at->tv_sec - to.tv_sec;
20 if ((to.tv_nsec = at->tv_nsec - to.tv_nsec) < 0) {
22 to.tv_nsec += 1000000000;
24 if (to.tv_sec < 0) return ETIMEDOUT;
28 r = -__syscall_cp(SYS_futex, addr, FUTEX_WAIT|priv, val, top);
29 if (r == ENOSYS) r = -__syscall_cp(SYS_futex, addr, FUTEX_WAIT, val, top);
30 if (r != EINTR && r != ETIMEDOUT && r != ECANCELED) r = 0;
35 int __timedwait(volatile int *addr, int val,
36 clockid_t clk, const struct timespec *at, int priv)
39 __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
40 r = __timedwait_cp(addr, val, clk, at, priv);
41 __pthread_setcancelstate(cs, 0);