diff options
author | rpj <rpj> | 2004-10-08 12:03:18 +0000 |
---|---|---|
committer | rpj <rpj> | 2004-10-08 12:03:18 +0000 |
commit | 9da8fdcb33373b4b2e1de2a8b7af3ed4b5811245 (patch) | |
tree | 1e232efaa8472fbf0d61816995cb4fddc7e9b5ed /pthread_mutex_unlock.c | |
parent | b0cf9efa6afeb8a7dbddf124dae173a2d633c801 (diff) |
Mutex speedups
Diffstat (limited to 'pthread_mutex_unlock.c')
-rw-r--r-- | pthread_mutex_unlock.c | 22 |
1 files changed, 7 insertions, 15 deletions
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 |