about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/thread/pthread_mutex_lock.c6
-rw-r--r--src/thread/pthread_mutex_trylock.c2
2 files changed, 6 insertions, 2 deletions
diff --git a/src/thread/pthread_mutex_lock.c b/src/thread/pthread_mutex_lock.c
index 15ede3f5..82556141 100644
--- a/src/thread/pthread_mutex_lock.c
+++ b/src/thread/pthread_mutex_lock.c
@@ -3,7 +3,11 @@
 int pthread_mutex_lock(pthread_mutex_t *m)
 {
 	int r;
-	while ((r=pthread_mutex_trylock(m)) == EBUSY)
+	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;
 }
diff --git a/src/thread/pthread_mutex_trylock.c b/src/thread/pthread_mutex_trylock.c
index 2dad7bbf..25b9e869 100644
--- a/src/thread/pthread_mutex_trylock.c
+++ b/src/thread/pthread_mutex_trylock.c
@@ -11,7 +11,7 @@ int pthread_mutex_trylock(pthread_mutex_t *m)
 
 	if (m->_m_owner == tid) {
 		if (m->_m_type != PTHREAD_MUTEX_RECURSIVE)
-			return EDEADLK;
+			return EBUSY;
 		if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN;
 		m->_m_count++;
 		return 0;