about summary refs log tree commit diff
path: root/src/thread/pthread_mutex_lock.c
blob: 56111ec84f8951c09bd06c54731a3a3085c1bf07 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include "pthread_impl.h"

int pthread_mutex_lock(pthread_mutex_t *m)
{
	int r;
	while ((r=pthread_mutex_trylock(m)) == EBUSY) {
		if (!(r=m->_m_lock)) continue;
		if (m->_m_type == PTHREAD_MUTEX_ERRORCHECK
		 && r == pthread_self()->tid)
			return EDEADLK;
		__wait(&m->_m_lock, &m->_m_waiters, r, 0);
	}
	return r;
}