diff options
author | rpj <rpj> | 2004-10-16 02:34:44 +0000 |
---|---|---|
committer | rpj <rpj> | 2004-10-16 02:34:44 +0000 |
commit | 45b1b8cb2a6588f9316f780d8cefe11c181a9a17 (patch) | |
tree | 24753e298d9933d48d764177baf183ef97f04156 /pthread_mutex_unlock.c | |
parent | 9da8fdcb33373b4b2e1de2a8b7af3ed4b5811245 (diff) |
Mutex speedups cont'd
Diffstat (limited to 'pthread_mutex_unlock.c')
-rw-r--r-- | pthread_mutex_unlock.c | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/pthread_mutex_unlock.c b/pthread_mutex_unlock.c index d853178..e28b38a 100644 --- a/pthread_mutex_unlock.c +++ b/pthread_mutex_unlock.c @@ -61,30 +61,26 @@ pthread_mutex_unlock (pthread_mutex_t * mutex) { LONG idx; - idx = (LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE ((PTW32_INTERLOCKED_LPLONG) - &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) -1, - (PTW32_INTERLOCKED_LONG) 0); - + idx = (LONG) PTW32_INTERLOCKED_EXCHANGE ((LPLONG) &mx->lock_idx, + (LONG) 0); if (idx != 0) { - if (idx > 0) + if (idx < 0) { - mx->lock_idx = -1; /* Someone may be waiting on that mutex */ - if (sem_post (&mx->wait_sema) != 0) + if (SetEvent (mx->event) == 0) { - result = errno; + result = EINVAL; } - } - else - { - /* - * Was not locked (so can't be owned by us). - */ - result = EPERM; } } + else + { + /* + * Was not locked (so can't be owned by us). + */ + result = EPERM; + } } else { @@ -95,13 +91,13 @@ pthread_mutex_unlock (pthread_mutex_t * mutex) { mx->ownerThread = NULL; - if (InterlockedDecrement (&mx->lock_idx) >= 0) + if ((LONG) PTW32_INTERLOCKED_EXCHANGE ((LPLONG) &mx->lock_idx, + (LONG) 0) < 0) { /* Someone may be waiting on that mutex */ - mx->lock_idx = -1; - if (sem_post (&mx->wait_sema) != 0) + if (SetEvent (mx->event) == 0) { - result = errno; + result = EINVAL; } } } |