13728282df2313b8b4ae2f1b19cac0a6ec2c5861
[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         pthread_testcancel();
13
14         pthread_cleanup_push(relock, m);
15         c->_c_block = 1;
16         if ((r=pthread_mutex_unlock(m))) return r;
17
18         do e = __timedwait_cp(&c->_c_block, 1, c->_c_clock, ts, 0);
19         while (e == EINTR);
20
21         pthread_cleanup_pop(0);
22         if ((r=pthread_mutex_lock(m))) return r;
23
24         pthread_testcancel();
25         return e;
26 }