mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-09 23:00:07 +00:00
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.
This commit is contained in:
parent
65fa1dec4e
commit
47e5d2a8b1
@ -1,3 +1,13 @@
|
||||
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.
|
||||
|
||||
2001-05-01 Kaz Kylheku <kaz@ashi.footprints.net>
|
||||
|
||||
Memory barrier overhaul following line by line inspection.
|
||||
|
@ -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))
|
||||
|
@ -104,10 +104,6 @@ static inline void __pthread_init_lock(struct _pthread_fastlock * lock)
|
||||
|
||||
static inline int __pthread_trylock (struct _pthread_fastlock * lock)
|
||||
{
|
||||
#if defined HAS_COMPARE_AND_SWAP
|
||||
long oldstatus;
|
||||
#endif
|
||||
|
||||
#if defined TEST_FOR_COMPARE_AND_SWAP
|
||||
if (!__pthread_has_cas)
|
||||
#endif
|
||||
@ -119,8 +115,7 @@ static inline int __pthread_trylock (struct _pthread_fastlock * lock)
|
||||
|
||||
#if defined HAS_COMPARE_AND_SWAP
|
||||
do {
|
||||
oldstatus = lock->__status;
|
||||
if (oldstatus != 0) return EBUSY;
|
||||
if (lock->__status != 0) return EBUSY;
|
||||
} while(! __compare_and_swap(&lock->__status, 0, 1));
|
||||
return 0;
|
||||
#endif
|
||||
@ -146,10 +141,6 @@ static inline void __pthread_alt_init_lock(struct _pthread_fastlock * lock)
|
||||
|
||||
static inline int __pthread_alt_trylock (struct _pthread_fastlock * lock)
|
||||
{
|
||||
#if defined HAS_COMPARE_AND_SWAP
|
||||
long oldstatus;
|
||||
#endif
|
||||
|
||||
#if defined TEST_FOR_COMPARE_AND_SWAP
|
||||
if (!__pthread_has_cas)
|
||||
#endif
|
||||
@ -173,8 +164,7 @@ static inline int __pthread_alt_trylock (struct _pthread_fastlock * lock)
|
||||
|
||||
#if defined HAS_COMPARE_AND_SWAP
|
||||
do {
|
||||
oldstatus = lock->__status;
|
||||
if (oldstatus != 0) return EBUSY;
|
||||
if (lock->__status != 0) return EBUSY;
|
||||
} while(! compare_and_swap(&lock->__status, 0, 1, &lock->__spinlock));
|
||||
return 0;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user