7 static int do_wait(volatile int *addr
, int val
,
8 clockid_t clk
, const struct timespec
*at
, int priv
)
11 struct timespec to
, *top
=0;
14 if (at
->tv_nsec
>= 1000000000UL) return EINVAL
;
15 if (clock_gettime(clk
, &to
)) return EINVAL
;
16 to
.tv_sec
= at
->tv_sec
- to
.tv_sec
;
17 if ((to
.tv_nsec
= at
->tv_nsec
- to
.tv_nsec
) < 0) {
19 to
.tv_nsec
+= 1000000000;
21 if (to
.tv_sec
< 0) return ETIMEDOUT
;
25 r
= -__syscall_cp(SYS_futex
, addr
, FUTEX_WAIT
, val
, top
);
26 if (r
== EINTR
|| r
== EINVAL
|| r
== ETIMEDOUT
) return r
;
30 int __timedwait(volatile int *addr
, int val
,
31 clockid_t clk
, const struct timespec
*at
,
32 void (*cleanup
)(void *), void *arg
, int priv
)
36 if (!cleanup
) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE
, &cs
);
37 pthread_cleanup_push(cleanup
, arg
);
39 r
= do_wait(addr
, val
, clk
, at
, priv
);
41 pthread_cleanup_pop(0);
42 if (!cleanup
) pthread_setcancelstate(cs
, 0);