From 45b1b8cb2a6588f9316f780d8cefe11c181a9a17 Mon Sep 17 00:00:00 2001 From: rpj Date: Sat, 16 Oct 2004 02:34:44 +0000 Subject: Mutex speedups cont'd --- pthread_mutex_unlock.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) (limited to 'pthread_mutex_unlock.c') 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; } } } -- cgit v1.2.3