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_lock.c | |
parent | 9da8fdcb33373b4b2e1de2a8b7af3ed4b5811245 (diff) |
Mutex speedups cont'd
Diffstat (limited to 'pthread_mutex_lock.c')
-rw-r--r-- | pthread_mutex_lock.c | 73 |
1 files changed, 26 insertions, 47 deletions
diff --git a/pthread_mutex_lock.c b/pthread_mutex_lock.c index 6695907..7be77b5 100644 --- a/pthread_mutex_lock.c +++ b/pthread_mutex_lock.c @@ -44,7 +44,6 @@ int pthread_mutex_lock (pthread_mutex_t * mutex) { int result = 0; - LONG c; pthread_mutex_t mx; /* @@ -69,40 +68,29 @@ pthread_mutex_lock (pthread_mutex_t * mutex) if (mx->kind == PTHREAD_MUTEX_NORMAL) { - if ((c = (LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( - (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 0, - (PTW32_INTERLOCKED_LONG) -1)) != -1) + if ((LONG) PTW32_INTERLOCKED_EXCHANGE( + (LPLONG) &mx->lock_idx, + (LONG) 1) != 0) { - do + while ((LONG) PTW32_INTERLOCKED_EXCHANGE( + (LPLONG) &mx->lock_idx, + (LONG) -1) != 0) { - if (c == 1 || - (LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( - (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1, - (PTW32_INTERLOCKED_LONG) 0) != -1) - { - if (ptw32_semwait (&mx->wait_sema) != 0) - { - result = errno; - break; - } - } + if (WAIT_OBJECT_0 != WaitForSingleObject (mx->event, INFINITE)) + { + result = EINVAL; + break; + } } - while ((c = (LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( - (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1, - (PTW32_INTERLOCKED_LONG) -1)) != -1); } } else { pthread_t self = pthread_self(); - if ((c = (LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( - (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 0, - (PTW32_INTERLOCKED_LONG) -1)) == -1) + if ((LONG) PTW32_INTERLOCKED_EXCHANGE( + (LPLONG) &mx->lock_idx, + (LONG) 1) == 0) { mx->recursive_count = 1; mx->ownerThread = self; @@ -122,30 +110,21 @@ pthread_mutex_lock (pthread_mutex_t * mutex) } else { - do + while ((LONG) PTW32_INTERLOCKED_EXCHANGE( + (LPLONG) &mx->lock_idx, + (LONG) -1) != 0) { - if (c == 1 || - (LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( - (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1, - (PTW32_INTERLOCKED_LONG) 0) != -1) + if (WAIT_OBJECT_0 == WaitForSingleObject (mx->event, INFINITE)) { - if (ptw32_semwait (&mx->wait_sema) == 0) - { - mx->recursive_count = 1; - mx->ownerThread = self; - } - else - { - result = errno; - break; - } + mx->recursive_count = 1; + mx->ownerThread = self; + } + else + { + result = EINVAL; + break; } - } - while ((c = (LONG) PTW32_INTERLOCKED_COMPARE_EXCHANGE( - (PTW32_INTERLOCKED_LPLONG) &mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 1, - (PTW32_INTERLOCKED_LONG) -1)) != -1); + } } } } |