1 #include "pthread_impl.h"
3 int pthread_mutex_trylock(pthread_mutex_t *m)
9 if (m->_m_type == PTHREAD_MUTEX_NORMAL)
10 return a_swap(&m->_m_lock, EBUSY);
12 self = pthread_self();
13 tid = self->tid | 0x80000000;
15 if (m->_m_type >= 4) {
16 if (!self->robust_list.off)
17 __syscall(SYS_set_robust_list,
18 &self->robust_list, 3*sizeof(long));
19 self->robust_list.off = (char*)&m->_m_lock-(char *)&m->_m_next;
20 self->robust_list.pending = &m->_m_next;
23 if (m->_m_lock == tid && (m->_m_type&3) == PTHREAD_MUTEX_RECURSIVE) {
24 if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN;
30 if ((own && !(own & 0x40000000)) || a_cas(&m->_m_lock, own, tid)!=own)
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;