1 #include "pthread_impl.h"
3 int pthread_mutex_trylock(pthread_mutex_t *m)
5 if (m->__type == PTHREAD_MUTEX_RECURSIVE) {
6 pthread_t self = pthread_self();
7 if (m->__owner == self) {
8 if ((unsigned)m->__lock >= INT_MAX) return EAGAIN;
12 if (a_fetch_add(&m->__lock, 1)) {
13 if (a_fetch_add(&m->__lock, -1)==1 && m->__waiters)
14 __wake(&m->__lock, 1, 0);
21 if (a_xchg(&m->__lock, 1))
22 if (m->__type == PTHREAD_MUTEX_ERRORCHECK
23 && m->__owner == pthread_self()) return EDEADLK;
25 if (m->__type == PTHREAD_MUTEX_ERRORCHECK)
26 m->__owner = pthread_self();