reorganize pthread data structures and move the definitions to alltypes.h
[musl] / src / thread / pthread_mutex_timedlock.c
1 #include "pthread_impl.h"
2
3 int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *at)
4 {
5         int r, w=0;
6         while ((r=pthread_mutex_trylock(m)) == EBUSY) {
7                 if (!w) a_inc(&m->_m_waiters), w++;
8                 if (__timedwait(&m->_m_lock, 1, CLOCK_REALTIME, at, 0) == ETIMEDOUT) {
9                         if (w) a_dec(&m->_m_waiters);
10                         return ETIMEDOUT;
11                 }
12         }
13         if (w) a_dec(&m->_m_waiters);
14         return r;
15 }