6 #include "pthread_impl.h"
8 static volatile int dummy = 0;
9 weak_alias(dummy, __eintr_valid_flag);
11 int __timedwait_cp(volatile int *addr, int val,
12 clockid_t clk, const struct timespec *at, int priv)
15 struct timespec to, *top=0;
17 if (priv) priv = FUTEX_PRIVATE;
20 if (at->tv_nsec >= 1000000000UL) return EINVAL;
21 if (__clock_gettime(clk, &to)) return EINVAL;
22 to.tv_sec = at->tv_sec - to.tv_sec;
23 if ((to.tv_nsec = at->tv_nsec - to.tv_nsec) < 0) {
25 to.tv_nsec += 1000000000;
27 if (to.tv_sec < 0) return ETIMEDOUT;
31 r = -__syscall_cp(SYS_futex, addr, FUTEX_WAIT|priv, val, top);
32 if (r == ENOSYS) r = -__syscall_cp(SYS_futex, addr, FUTEX_WAIT, val, top);
33 if (r != EINTR && r != ETIMEDOUT && r != ECANCELED) r = 0;
34 /* Mitigate bug in old kernels wrongly reporting EINTR for non-
35 * interrupting (SA_RESTART) signal handlers. This is only practical
36 * when NO interrupting signal handlers have been installed, and
37 * works by sigaction tracking whether that's the case. */
38 if (r == EINTR && !__eintr_valid_flag) r = 0;
43 int __timedwait(volatile int *addr, int val,
44 clockid_t clk, const struct timespec *at, int priv)
47 __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
48 r = __timedwait_cp(addr, val, clk, at, priv);
49 __pthread_setcancelstate(cs, 0);