dummy implementation of set_thread_area
[musl] / src / thread / __timedwait.c
1 #include <pthread.h>
2 #include <time.h>
3 #include <errno.h>
4 #include "futex.h"
5 #include "syscall.h"
6
7 static int do_wait(volatile int *addr, int val,
8         clockid_t clk, const struct timespec *at, int priv)
9 {
10         int r;
11         struct timespec to, *top=0;
12
13         if (at) {
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) {
18                         to.tv_sec--;
19                         to.tv_nsec += 1000000000;
20                 }
21                 if (to.tv_sec < 0) return ETIMEDOUT;
22                 top = &to;
23         }
24
25         r = -__syscall_cp(SYS_futex, addr, FUTEX_WAIT, val, top);
26         if (r == EINTR || r == EINVAL || r == ETIMEDOUT) return r;
27         return 0;
28 }
29
30 int __timedwait(volatile int *addr, int val,
31         clockid_t clk, const struct timespec *at,
32         void (*cleanup)(void *), void *arg, int priv)
33 {
34         int r, cs;
35
36         if (!cleanup) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
37         pthread_cleanup_push(cleanup, arg);
38
39         r = do_wait(addr, val, clk, at, priv);
40
41         pthread_cleanup_pop(0);
42         if (!cleanup) pthread_setcancelstate(cs, 0);
43
44         return r;
45 }