From b962fefe8733a2fd7911090b3e8565eff3469048 Mon Sep 17 00:00:00 2001 From: neal Date: Wed, 23 Jan 2008 22:53:30 +0000 Subject: 2008-01-23 Neal H. Walfield * mutex.h (ss_mutex_unlock): Correctly test whether there are waiters. * rmutex.h (ss_rmutex_lock): Save the value of LOCKP->COUNT before unlocking the LOCKP->LOCK. After unlocking, use the cached value. (ss_rmutex_unlock): Improve assert. Only clear LOCKP->OWNER and wake a waiter if LOCKP->COUNT drops to 0. (ss_rmutex_trylock): Correctly test whether we got LOCKP->LOCK. --- hurd/mutex.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'hurd/mutex.h') diff --git a/hurd/mutex.h b/hurd/mutex.h index 3e21eee..3f50934 100644 --- a/hurd/mutex.h +++ b/hurd/mutex.h @@ -89,8 +89,9 @@ ss_mutex_unlock (__const char *caller, int line, ss_mutex_t *lockp) { /* We rely on the knowledge that unlocked is 0, locked and no waiters is 1 and locked with waiters is 2. Thus if *lockp is 1, - an atomic dec yields 0 and we know that there are no waiters. */ - if (! atomic_decrement_and_test (lockp)) + an atomic dec yields 1 (the old value) and we know that there are + no waiters. */ + if (atomic_decrement_and_test (lockp) != _MUTEX_LOCKED) /* There are waiters. */ { *lockp = 0; -- cgit v1.2.3