summaryrefslogtreecommitdiff
path: root/pthread_mutex_lock.c
diff options
context:
space:
mode:
authorrpj <rpj>2004-10-01 07:17:09 +0000
committerrpj <rpj>2004-10-01 07:17:09 +0000
commitb0cf9efa6afeb8a7dbddf124dae173a2d633c801 (patch)
tree8f208f15bd63cf69ae9e2ceb2d523296db8bca76 /pthread_mutex_lock.c
parent531ca4db4794aab863a898b4d079ccd59b424b25 (diff)
Mutex speedups
Diffstat (limited to 'pthread_mutex_lock.c')
-rw-r--r--pthread_mutex_lock.c64
1 files changed, 36 insertions, 28 deletions
diff --git a/pthread_mutex_lock.c b/pthread_mutex_lock.c
index f92b39b..b733801 100644
--- a/pthread_mutex_lock.c
+++ b/pthread_mutex_lock.c
@@ -46,11 +46,9 @@ pthread_mutex_lock (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
@@ -68,41 +66,51 @@ pthread_mutex_lock (pthread_mutex_t * mutex)
mx = *mutex;
- if (0 == InterlockedIncrement (&mx->lock_idx))
+ 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);
+ if (0 != InterlockedIncrement (&mx->lock_idx))
+ {
+ if (ptw32_semwait (&mx->wait_sema) != 0)
+ {
+ result = errno;
+ }
+ }
}
else
{
- if (mx->kind != PTHREAD_MUTEX_FAST_NP &&
- pthread_equal (mx->ownerThread, pthread_self ()))
+ if (0 == InterlockedIncrement (&mx->lock_idx))
{
- (void) InterlockedDecrement (&mx->lock_idx);
-
- if (mx->kind == PTHREAD_MUTEX_RECURSIVE_NP)
- {
- mx->recursive_count++;
- }
- else
- {
- result = EDEADLK;
- }
+ mx->recursive_count = 1;
+ mx->ownerThread = pthread_self ();
}
else
{
- if (ptw32_semwait (&mx->wait_sema) == 0)
+ pthread_t self = pthread_self();
+
+ if (pthread_equal (mx->ownerThread, self))
{
- mx->recursive_count = 1;
- mx->ownerThread = (mx->kind != PTHREAD_MUTEX_FAST_NP
- ? pthread_self ()
- : (pthread_t) PTW32_MUTEX_OWNER_ANONYMOUS);
+ (void) InterlockedDecrement (&mx->lock_idx);
+
+ if (mx->kind == PTHREAD_MUTEX_RECURSIVE)
+ {
+ mx->recursive_count++;
+ }
+ else
+ {
+ result = EDEADLK;
+ }
}
else
{
- result = errno;
+ if (ptw32_semwait (&mx->wait_sema) == 0)
+ {
+ mx->recursive_count = 1;
+ mx->ownerThread = self;
+ }
+ else
+ {
+ result = errno;
+ }
}
}
}