diff options
author | rpj <rpj> | 2004-10-01 07:17:09 +0000 |
---|---|---|
committer | rpj <rpj> | 2004-10-01 07:17:09 +0000 |
commit | b0cf9efa6afeb8a7dbddf124dae173a2d633c801 (patch) | |
tree | 8f208f15bd63cf69ae9e2ceb2d523296db8bca76 /pthread_mutex_trylock.c | |
parent | 531ca4db4794aab863a898b4d079ccd59b424b25 (diff) |
Mutex speedups
Diffstat (limited to 'pthread_mutex_trylock.c')
-rw-r--r-- | pthread_mutex_trylock.c | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/pthread_mutex_trylock.c b/pthread_mutex_trylock.c index 6f137f0..bba8ed2 100644 --- a/pthread_mutex_trylock.c +++ b/pthread_mutex_trylock.c @@ -44,10 +44,9 @@ pthread_mutex_trylock (pthread_mutex_t * mutex) int result = 0; pthread_mutex_t mx; - if (mutex == NULL || *mutex == NULL) - { - return EINVAL; - } + /* + * Let the system deal with invalid pointers. + */ /* * We do a quick check to see if we need to do more work @@ -57,36 +56,36 @@ pthread_mutex_trylock (pthread_mutex_t * mutex) */ if (*mutex >= PTHREAD_ERRORCHECK_MUTEX_INITIALIZER) { - result = ptw32_mutex_check_need_init (mutex); + if ((result = ptw32_mutex_check_need_init (mutex)) != 0) + { + return (result); + } } mx = *mutex; - if (result == 0) + if ((PTW32_INTERLOCKED_LONG) -1 == + ptw32_interlocked_compare_exchange ((PTW32_INTERLOCKED_LPLONG) & + mx->lock_idx, + (PTW32_INTERLOCKED_LONG) 0, + (PTW32_INTERLOCKED_LONG) -1)) { - if ((PTW32_INTERLOCKED_LONG) PTW32_MUTEX_LOCK_IDX_INIT == - ptw32_interlocked_compare_exchange ((PTW32_INTERLOCKED_LPLONG) & - mx->lock_idx, - (PTW32_INTERLOCKED_LONG) 0, - (PTW32_INTERLOCKED_LONG) - PTW32_MUTEX_LOCK_IDX_INIT)) + if (mx->kind != PTHREAD_MUTEX_NORMAL) { mx->recursive_count = 1; - mx->ownerThread = (mx->kind != PTHREAD_MUTEX_FAST_NP - ? pthread_self () - : (pthread_t) PTW32_MUTEX_OWNER_ANONYMOUS); + mx->ownerThread = pthread_self (); + } + } + else + { + if (mx->kind == PTHREAD_MUTEX_RECURSIVE && + pthread_equal (mx->ownerThread, pthread_self ())) + { + mx->recursive_count++; } else { - if (mx->kind == PTHREAD_MUTEX_RECURSIVE_NP && - pthread_equal (mx->ownerThread, pthread_self ())) - { - mx->recursive_count++; - } - else - { - result = EBUSY; - } + result = EBUSY; } } |