initial check-in, version 0.5.0
[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         CANCELPT(0);
12
13         pthread_cleanup_push(relock, m);
14         c->__block = 1;
15         if ((r=pthread_mutex_unlock(m))) return r;
16
17         CANCELPT(1);
18         e = __timedwait(&c->__block, 1, CLOCK_REALTIME, ts, 0);
19         CANCELPT(0);
20
21         pthread_cleanup_pop(0);
22         if ((r=pthread_mutex_lock(m))) return r;
23
24         CANCELPT(0);
25         return e;
26 }