2011-02-12 00:22:29 -05:00
|
|
|
#include "pthread_impl.h"
|
|
|
|
|
|
|
|
int pthread_mutex_lock(pthread_mutex_t *m)
|
|
|
|
{
|
|
|
|
int r;
|
2011-03-30 08:58:25 -04:00
|
|
|
|
2011-04-14 14:39:57 -04:00
|
|
|
if (m->_m_type == PTHREAD_MUTEX_NORMAL && !a_swap(&m->_m_lock, EBUSY))
|
2011-03-30 08:58:25 -04:00
|
|
|
return 0;
|
|
|
|
|
2011-03-16 16:25:00 -04:00
|
|
|
while ((r=pthread_mutex_trylock(m)) == EBUSY) {
|
2011-03-17 20:41:37 -04:00
|
|
|
if (!(r=m->_m_lock) || (r&0x40000000)) continue;
|
|
|
|
if ((m->_m_type&3) == PTHREAD_MUTEX_ERRORCHECK
|
|
|
|
&& (r&0x1fffffff) == pthread_self()->tid)
|
2011-03-16 16:25:00 -04:00
|
|
|
return EDEADLK;
|
2011-03-17 12:21:32 -04:00
|
|
|
__wait(&m->_m_lock, &m->_m_waiters, r, 0);
|
2011-03-16 16:25:00 -04:00
|
|
|
}
|
2011-02-12 00:22:29 -05:00
|
|
|
return r;
|
|
|
|
}
|