summaryrefslogtreecommitdiff
path: root/pthread_mutex_unlock.c
diff options
context:
space:
mode:
authorrpj <rpj>2004-10-16 02:34:44 +0000
committerrpj <rpj>2004-10-16 02:34:44 +0000
commit45b1b8cb2a6588f9316f780d8cefe11c181a9a17 (patch)
tree24753e298d9933d48d764177baf183ef97f04156 /pthread_mutex_unlock.c
parent9da8fdcb33373b4b2e1de2a8b7af3ed4b5811245 (diff)
Mutex speedups cont'd
Diffstat (limited to 'pthread_mutex_unlock.c')
-rw-r--r--pthread_mutex_unlock.c36
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;
}
}
}