1 #include "pthread_impl.h"
3 int pthread_mutex_trylock(pthread_mutex_t *m)
8 if (m->_m_type == PTHREAD_MUTEX_NORMAL)
9 return a_cas(&m->_m_lock, 0, EBUSY) & EBUSY;
11 self = pthread_self();
14 if (m->_m_type >= 4) {
15 if (!self->robust_list.off)
16 __syscall(SYS_set_robust_list,
17 &self->robust_list, 3*sizeof(long));
18 self->robust_list.off = (char*)&m->_m_lock-(char *)&m->_m_next;
19 self->robust_list.pending = &m->_m_next;
23 own = old & 0x7fffffff;
24 if (own == tid && (m->_m_type&3) == PTHREAD_MUTEX_RECURSIVE) {
25 if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN;
30 if ((own && !(own & 0x40000000)) || a_cas(&m->_m_lock, old, tid)!=old)
35 if (m->_m_type < 4) return 0;
37 if (m->_m_type >= 8) {
39 return ENOTRECOVERABLE;
41 m->_m_next = self->robust_list.head;
42 m->_m_prev = &self->robust_list.head;
43 if (self->robust_list.head)
44 self->robust_list.head[-1] = &m->_m_next;
45 self->robust_list.head = &m->_m_next;
46 self->robust_list.pending = 0;