From 9da8fdcb33373b4b2e1de2a8b7af3ed4b5811245 Mon Sep 17 00:00:00 2001 From: rpj Date: Fri, 8 Oct 2004 12:03:18 +0000 Subject: Mutex speedups --- pthread_mutex_unlock.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'pthread_mutex_unlock.c') diff --git a/pthread_mutex_unlock.c b/pthread_mutex_unlock.c index 7b20d79..d853178 100644 --- a/pthread_mutex_unlock.c +++ b/pthread_mutex_unlock.c @@ -61,7 +61,7 @@ pthread_mutex_unlock (pthread_mutex_t * mutex) { LONG idx; - idx = (LONG) ptw32_interlocked_compare_exchange ((PTW32_INTERLOCKED_LPLONG) + idx = (LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, (PTW32_INTERLOCKED_LONG) -1, (PTW32_INTERLOCKED_LONG) 0); @@ -70,18 +70,12 @@ pthread_mutex_unlock (pthread_mutex_t * mutex) { if (idx > 0) { - EnterCriticalSection (&mx->wait_cs); - - if (InterlockedDecrement (&mx->lock_idx) >= 0) + mx->lock_idx = -1; + /* Someone may be waiting on that mutex */ + if (sem_post (&mx->wait_sema) != 0) { - /* Someone is waiting on that mutex */ - if (sem_post (&mx->wait_sema) != 0) - { - result = errno; - } + result = errno; } - - LeaveCriticalSection (&mx->wait_cs); } else { @@ -100,18 +94,16 @@ pthread_mutex_unlock (pthread_mutex_t * mutex) || 0 == --mx->recursive_count) { mx->ownerThread = NULL; - EnterCriticalSection (&mx->wait_cs); if (InterlockedDecrement (&mx->lock_idx) >= 0) { - /* Someone is waiting on that mutex */ + /* Someone may be waiting on that mutex */ + mx->lock_idx = -1; if (sem_post (&mx->wait_sema) != 0) { result = errno; } } - - LeaveCriticalSection (&mx->wait_cs); } } else -- cgit v1.2.3