diff options
author | Ulrich Drepper <drepper@redhat.com> | 2001-05-24 23:38:52 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2001-05-24 23:38:52 +0000 |
commit | 47e5d2a8b132c73bc0659baad25714326fb333c9 (patch) | |
tree | 36c83a82b882e1d624374ac0956b8a870881ee52 /linuxthreads/spinlock.c | |
parent | 65fa1dec4ec6d800ba9e91abe0e4ae8208b9905e (diff) | |
download | glibc-47e5d2a8b132c73bc0659baad25714326fb333c9.zip glibc-47e5d2a8b132c73bc0659baad25714326fb333c9.tar.gz glibc-47e5d2a8b132c73bc0659baad25714326fb333c9.tar.bz2 |
Update.
2001-05-24 Ulrich Drepper <drepper@redhat.com>
* spinlock.c (__pthread_lock) [HAS_COMPARE_AND_SWAP]: Before doing any
serious work try once whether the lock is uncontested.
Remove duplicate reading of __status before loop.
Change suggested by Hans Boehm <hans_boehm@hp.com>.
* spinlock.h (__pthread_trylock): Remove need for oldstatus variable.
(__pthread_alt_trylock): Likewise.
Diffstat (limited to 'linuxthreads/spinlock.c')
-rw-r--r-- | linuxthreads/spinlock.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/linuxthreads/spinlock.c b/linuxthreads/spinlock.c index 927cb19..199386a 100644 --- a/linuxthreads/spinlock.c +++ b/linuxthreads/spinlock.c @@ -64,8 +64,8 @@ void internal_function __pthread_lock(struct _pthread_fastlock * lock, { #if defined HAS_COMPARE_AND_SWAP long oldstatus, newstatus; - int successful_seizure, spurious_wakeup_count = 0; - int spin_count = 0; + int successful_seizure, spurious_wakeup_count; + int spin_count; #endif #if defined TEST_FOR_COMPARE_AND_SWAP @@ -79,6 +79,14 @@ void internal_function __pthread_lock(struct _pthread_fastlock * lock, #endif #if defined HAS_COMPARE_AND_SWAP + /* First try it without preparation. Maybe it's a completely + uncontested lock. */ + if (lock->__status == 0 && __compare_and_swap (&lock->__status, 0, 1)) + return; + + spurious_wakeup_count = 0; + spin_count = 0; + again: /* On SMP, try spinning to get the lock. */ @@ -174,8 +182,6 @@ int __pthread_unlock(struct _pthread_fastlock * lock) WRITE_MEMORY_BARRIER(); again: - oldstatus = lock->__status; - while ((oldstatus = lock->__status) == 1) { if (__compare_and_swap_with_release_semantics(&lock->__status, oldstatus, 0)) |