don't expose EAGAIN, etc. from timed futex wait to caller
[musl] / src / thread / __timedwait.c
1 #include <time.h>
2 #include <errno.h>
3 #include "futex.h"
4 #define SYSCALL_RETURN_ERRNO
5 #include "syscall.h"
6 #include <stdio.h>
7 int __timedwait(volatile int *addr, int val, clockid_t clk, const struct timespec *at, int priv)
8 {
9         int r;
10         struct timespec to;
11         if (at) {
12                 clock_gettime(clk, &to);
13                 to.tv_sec = at->tv_sec - to.tv_sec;
14                 if ((to.tv_nsec = at->tv_nsec - to.tv_nsec) < 0) {
15                         to.tv_sec--;
16                         to.tv_nsec += 1000000000;
17                 }
18                 if (to.tv_sec < 0) return ETIMEDOUT;
19         }
20         if (priv) priv = 128; priv=0;
21         r = syscall4(__NR_futex, (long)addr, FUTEX_WAIT | priv, val, at ? (long)&to : 0);
22         if (r == ETIMEDOUT) return r;
23         return 0;
24 }