ee874a3601ef6b2350cbbdc92a877e8bdc9c227b
[musl] / src / thread / pthread_cond_timedwait.c
1 #include "pthread_impl.h"
2
3 static void relock(void *m)
4 {
5         pthread_mutex_lock(m);
6 }
7
8 int pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m, const struct timespec *ts)
9 {
10         int r, e=0;
11
12         if (ts && ts->tv_nsec >= 1000000000UL)
13                 return EINVAL;
14
15         pthread_testcancel();
16
17         c->_c_block = 1;
18         if ((r=pthread_mutex_unlock(m))) return r;
19
20         do e = __timedwait(&c->_c_block, 1, c->_c_clock, ts, relock, m, 0);
21         while (e == EINTR);
22
23         if ((r=pthread_mutex_lock(m))) return r;
24
25         pthread_testcancel();
26         return e;
27 }