int pthread_mutex_consistent(pthread_mutex_t *m)
{
- if ((m->_m_type & 15) < 8) return EINVAL;
- if ((m->_m_lock & 0x3fffffff) != __pthread_self()->tid)
+ if (!(m->_m_type & 8)) return EINVAL;
+ if ((m->_m_lock & 0x7fffffff) != __pthread_self()->tid)
return EPERM;
m->_m_type -= 8;
return 0;
int r, t, priv = (m->_m_type & 128) ^ 128;
while ((r=pthread_mutex_trylock(m)) == EBUSY) {
- if (!(r=m->_m_lock) || (r&0x40000000)) continue;
+ if (!(r=m->_m_lock) || ((r&0x40000000) && (m->_m_type&4)))
+ continue;
if ((m->_m_type&3) == PTHREAD_MUTEX_ERRORCHECK
- && (r&0x1fffffff) == __pthread_self()->tid)
+ && (r&0x7fffffff) == __pthread_self()->tid)
return EDEADLK;
a_inc(&m->_m_waiters);
pthread_t self = __pthread_self();
int tid = self->tid;
- if (type >= 4) {
- if (!self->robust_list.off)
- __syscall(SYS_set_robust_list,
- &self->robust_list, 3*sizeof(long));
+ if (!self->robust_list.off) {
+ __syscall(SYS_set_robust_list, &self->robust_list, 3*sizeof(long));
self->robust_list.off = (char*)&m->_m_lock-(char *)&m->_m_next;
- self->robust_list.pending = &m->_m_next;
}
old = m->_m_lock;
return 0;
}
- if ((own && !(own & 0x40000000)) || a_cas(&m->_m_lock, old, tid)!=old)
- return EBUSY;
-
- if (type < 4) return 0;
+ self->robust_list.pending = &m->_m_next;
- if (type >= 8) {
- m->_m_lock = 0;
- return ENOTRECOVERABLE;
+ if ((own && (!(own & 0x40000000) || !(type & 4)))
+ || a_cas(&m->_m_lock, old, tid) != old) {
+ self->robust_list.pending = 0;
+ return EBUSY;
}
+
m->_m_next = self->robust_list.head;
m->_m_prev = &self->robust_list.head;
if (self->robust_list.head)
self->robust_list.head[-1] = &m->_m_next;
self->robust_list.head = &m->_m_next;
self->robust_list.pending = 0;
+
+ if (type < 4) return 0;
+
+ if (type >= 8) {
+ m->_m_lock = 0;
+ return ENOTRECOVERABLE;
+ }
+
if (own) {
m->_m_count = 0;
m->_m_type += 8;
pthread_t self;
int waiters = m->_m_waiters;
int cont;
- int robust = 0;
int type = m->_m_type & 15;
int priv = (m->_m_type & 128) ^ 128;
if (!m->_m_lock)
return EPERM;
self = __pthread_self();
- if ((m->_m_lock&0x1fffffff) != self->tid)
+ if ((m->_m_lock&0x7fffffff) != self->tid)
return EPERM;
if ((type&3) == PTHREAD_MUTEX_RECURSIVE && m->_m_count)
return m->_m_count--, 0;
- if (type >= 4) {
- robust = 1;
+ if (!priv) {
self->robust_list.pending = &m->_m_next;
- *(void **)m->_m_prev = m->_m_next;
- if (m->_m_next) ((void **)m->_m_next)[-1] = m->_m_prev;
__vm_lock_impl(+1);
}
+ *(void **)m->_m_prev = m->_m_next;
+ if (m->_m_next) ((void **)m->_m_next)[-1] = m->_m_prev;
}
cont = a_swap(&m->_m_lock, 0);
- if (robust) {
+ if (type != PTHREAD_MUTEX_NORMAL && !priv) {
self->robust_list.pending = 0;
__vm_unlock_impl();
}