aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/wasi/thread-stub/pthread_mutex_lock.c
blob: 9b380c50ec1fc6712a48c9a060187dfbcd2ea430 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "pthread_impl.h"

int __pthread_mutex_lock(pthread_mutex_t *m)
{
	/*
		_m_type[1:0] 	- type
		0 - normal
		1 - recursive
		2 - errorcheck
	*/
	if (m->_m_type&3 != PTHREAD_MUTEX_RECURSIVE) {
		if (m->_m_count) return EDEADLK;
		m->_m_count = 1;
	} else {
		if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN;
		m->_m_count++;
	}
	return 0;
}

weak_alias(__pthread_mutex_lock, pthread_mutex_lock);