1 #include "pthread_impl.h"
3 int __pthread_mutex_trylock_owner(pthread_mutex_t *m)
6 int type = m->_m_type & 15;
7 pthread_t self = __pthread_self();
10 if (!self->robust_list.off) {
11 __syscall(SYS_set_robust_list, &self->robust_list, 3*sizeof(long));
12 self->robust_list.off = (char*)&m->_m_lock-(char *)&m->_m_next;
16 own = old & 0x7fffffff;
17 if (own == tid && (type&3) == PTHREAD_MUTEX_RECURSIVE) {
18 if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN;
22 if (own == 0x40000000) return ENOTRECOVERABLE;
24 self->robust_list.pending = &m->_m_next;
26 if ((own && (!(own & 0x40000000) || !(type & 4)))
27 || a_cas(&m->_m_lock, old, tid) != old) {
28 self->robust_list.pending = 0;
32 m->_m_next = self->robust_list.head;
33 m->_m_prev = &self->robust_list.head;
34 if (self->robust_list.head)
35 self->robust_list.head[-1] = &m->_m_next;
36 self->robust_list.head = &m->_m_next;
37 self->robust_list.pending = 0;
48 int pthread_mutex_trylock(pthread_mutex_t *m)
50 if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL)
51 return a_cas(&m->_m_lock, 0, EBUSY) & EBUSY;
52 return __pthread_mutex_trylock_owner(m);