From 8d41d0ee72349d98a53abdda9eeef41d6044dc63 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 1 Nov 2008 14:30:09 +0000 Subject: [PATCH] Spotted by "daste": When unlocking the mutex owner must be set to -1 also for error check mutexes, otherwise the next pthread_mutex_lock() will fail. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28428 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/libroot/posix/pthread/pthread_mutex.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/system/libroot/posix/pthread/pthread_mutex.c b/src/system/libroot/posix/pthread/pthread_mutex.c index e344a3937f..5c40568ba4 100644 --- a/src/system/libroot/posix/pthread/pthread_mutex.c +++ b/src/system/libroot/posix/pthread/pthread_mutex.c @@ -160,13 +160,13 @@ pthread_mutex_unlock(pthread_mutex_t *mutex) if (mutex->owner != find_thread(NULL)) return EPERM; - if (MUTEX_TYPE(mutex) == PTHREAD_MUTEX_RECURSIVE) { - if (mutex->owner_count-- > 1) - return B_OK; - - mutex->owner = -1; + if (MUTEX_TYPE(mutex) == PTHREAD_MUTEX_RECURSIVE + && mutex->owner_count-- > 1) { + return B_OK; } + mutex->owner = -1; + if (atomic_add((vint32*)&mutex->count, -1) > 1) return release_sem(mutex->sem);