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

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