1 #include "pthread_impl.h"
3 int __pthread_mutex_trylock(pthread_mutex_t *);
5 int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at)
7 if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL
8 && !a_cas(&m->_m_lock, 0, EBUSY))
11 int type = m->_m_type;
12 int r, t, priv = (type & 128) ^ 128;
14 r = pthread_mutex_trylock(m);
15 if (r != EBUSY) return r;
18 while (spins-- && m->_m_lock && !m->_m_waiters) a_spin();
20 while ((r=__pthread_mutex_trylock(m)) == EBUSY) {
21 if (!(r=m->_m_lock) || ((r&0x40000000) && (type&4)))
23 if ((type&3) == PTHREAD_MUTEX_ERRORCHECK
24 && (r&0x7fffffff) == __pthread_self()->tid)
27 a_inc(&m->_m_waiters);
29 a_cas(&m->_m_lock, r, t);
30 r = __timedwait(&m->_m_lock, t, CLOCK_REALTIME, at, priv);
31 a_dec(&m->_m_waiters);
32 if (r && r != EINTR) break;
37 weak_alias(__pthread_mutex_timedlock, pthread_mutex_timedlock);