diff options
author | Ulrich Drepper <drepper@redhat.com> | 2004-06-03 16:04:11 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2004-06-03 16:04:11 +0000 |
commit | 75fcceded2cfc65e4879521fff4db6a620a96363 (patch) | |
tree | 6d0763c5a2e4b59ece4d57a87232d435d15a5f7f /nptl/sysdeps/pthread | |
parent | 322861e8b62dbca030a66f9ab37e6688b223c65f (diff) | |
download | glibc-75fcceded2cfc65e4879521fff4db6a620a96363.tar.gz glibc-75fcceded2cfc65e4879521fff4db6a620a96363.tar.xz glibc-75fcceded2cfc65e4879521fff4db6a620a96363.zip |
Update.
2004-06-03 Ulrich Drepper <drepper@redhat.com> * sysdeps/i386/i486/bits/atomic.h: Optimize a bit.
Diffstat (limited to 'nptl/sysdeps/pthread')
-rw-r--r-- | nptl/sysdeps/pthread/pthread_cond_broadcast.c | 22 | ||||
-rw-r--r-- | nptl/sysdeps/pthread/pthread_cond_signal.c | 15 | ||||
-rw-r--r-- | nptl/sysdeps/pthread/pthread_cond_timedwait.c | 26 | ||||
-rw-r--r-- | nptl/sysdeps/pthread/pthread_cond_wait.c | 28 |
4 files changed, 28 insertions, 63 deletions
diff --git a/nptl/sysdeps/pthread/pthread_cond_broadcast.c b/nptl/sysdeps/pthread/pthread_cond_broadcast.c index a42c579658..1eac8ecf83 100644 --- a/nptl/sysdeps/pthread/pthread_cond_broadcast.c +++ b/nptl/sysdeps/pthread/pthread_cond_broadcast.c @@ -41,35 +41,29 @@ __pthread_cond_broadcast (cond) /* Yes. Mark them all as woken. */ cond->__data.__wakeup_seq = cond->__data.__total_seq; cond->__data.__woken_seq = cond->__data.__total_seq; + cond->__data.__futex = (unsigned int) cond->__data.__total_seq * 2; + int futex_val = cond->__data.__futex; /* Signal that a broadcast happened. */ ++cond->__data.__broadcast_seq; /* We are done. */ lll_mutex_unlock (cond->__data.__lock); - /* The futex syscall operates on a 32-bit word. That is fine, - we just use the low 32 bits of the sequence counter. */ -#if BYTE_ORDER == LITTLE_ENDIAN - int *futex = ((int *) (&cond->__data.__wakeup_seq)); -#elif BYTE_ORDER == BIG_ENDIAN - int *futex = ((int *) (&cond->__data.__wakeup_seq)) + 1; -#else -# error "No valid byte order" -#endif - /* Do not use requeue for pshared condvars. */ if (cond->__data.__mutex == (void *) ~0l) goto wake_all; /* Wake everybody. */ pthread_mutex_t *mut = (pthread_mutex_t *) cond->__data.__mutex; - if (__builtin_expect (lll_futex_requeue (futex, 1, INT_MAX, - &mut->__data.__lock) == -EINVAL, - 0)) + /* lll_futex_requeue returns 0 for success and non-zero + for errors. */ + if (__builtin_expect (lll_futex_requeue (&cond->__data.__futex, 1, + INT_MAX, &mut->__data.__lock, + futex_val), 0)) { /* The requeue functionality is not available. */ wake_all: - lll_futex_wake (futex, INT_MAX); + lll_futex_wake (&cond->__data.__futex, INT_MAX); } /* That's all. */ diff --git a/nptl/sysdeps/pthread/pthread_cond_signal.c b/nptl/sysdeps/pthread/pthread_cond_signal.c index 76203ac2cc..f5623480f8 100644 --- a/nptl/sysdeps/pthread/pthread_cond_signal.c +++ b/nptl/sysdeps/pthread/pthread_cond_signal.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. +/* Copyright (C) 2003, 2004 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. @@ -40,19 +40,10 @@ __pthread_cond_signal (cond) { /* Yes. Mark one of them as woken. */ ++cond->__data.__wakeup_seq; - - /* The futex syscall operates on a 32-bit word. That is fine, - we just use the low 32 bits of the sequence counter. */ -#if BYTE_ORDER == LITTLE_ENDIAN - int *futex = ((int *) (&cond->__data.__wakeup_seq)); -#elif BYTE_ORDER == BIG_ENDIAN - int *futex = ((int *) (&cond->__data.__wakeup_seq)) + 1; -#else -# error "No valid byte order" -#endif + ++cond->__data.__futex; /* Wake one. */ - lll_futex_wake (futex, 1); + lll_futex_wake (&cond->__data.__futex, 1); } /* We are done. */ diff --git a/nptl/sysdeps/pthread/pthread_cond_timedwait.c b/nptl/sysdeps/pthread/pthread_cond_timedwait.c index 96b1029cf5..940b51b4be 100644 --- a/nptl/sysdeps/pthread/pthread_cond_timedwait.c +++ b/nptl/sysdeps/pthread/pthread_cond_timedwait.c @@ -66,6 +66,7 @@ __pthread_cond_timedwait (cond, mutex, abstime) /* We have one new user of the condvar. */ ++cond->__data.__total_seq; + ++cond->__data.__futex; /* Remember the mutex we are using here. If there is already a different address store this is a bad user bug. Do not store @@ -89,27 +90,17 @@ __pthread_cond_timedwait (cond, mutex, abstime) /* Remember the broadcast counter. */ cbuffer.bc_seq = cond->__data.__broadcast_seq; - /* The futex syscall operates on a 32-bit word. That is fine, we - just use the low 32 bits of the sequence counter. */ -#if BYTE_ORDER == LITTLE_ENDIAN - int *futex = ((int *) (&cond->__data.__wakeup_seq)); -#elif BYTE_ORDER == BIG_ENDIAN - int *futex = ((int *) (&cond->__data.__wakeup_seq)) + 1; -#else -# error "No valid byte order" -#endif - while (1) { struct timespec rt; { #ifdef __NR_clock_gettime INTERNAL_SYSCALL_DECL (err); - int val; - val = INTERNAL_SYSCALL (clock_gettime, err, 2, + int ret; + ret = INTERNAL_SYSCALL (clock_gettime, err, 2, cond->__data.__clock, &rt); # ifndef __ASSUME_POSIX_TIMERS - if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (val, err), 0)) + if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (ret, err), 0)) { struct timeval tv; (void) gettimeofday (&tv, NULL); @@ -149,15 +140,17 @@ __pthread_cond_timedwait (cond, mutex, abstime) goto timeout; } + unsigned int futex_val = cond->__data.__futex; + /* Prepare to wait. Release the condvar futex. */ lll_mutex_unlock (cond->__data.__lock); /* Enable asynchronous cancellation. Required by the standard. */ cbuffer.oldtype = __pthread_enable_asynccancel (); - /* Wait until woken by signal or broadcast. Note that we - truncate the 'val' value to 32 bits. */ - err = lll_futex_timed_wait (futex, (unsigned int) val, &rt); + /* Wait until woken by signal or broadcast. */ + err = lll_futex_timed_wait (&cond->__data.__futex, + futex_val, &rt); /* Disable asynchronous cancellation. */ __pthread_disable_asynccancel (cbuffer.oldtype); @@ -180,6 +173,7 @@ __pthread_cond_timedwait (cond, mutex, abstime) timeout: /* Yep. Adjust the counters. */ ++cond->__data.__wakeup_seq; + ++cond->__data.__futex; /* The error value. */ result = ETIMEDOUT; diff --git a/nptl/sysdeps/pthread/pthread_cond_wait.c b/nptl/sysdeps/pthread/pthread_cond_wait.c index 128f5a2d99..45187b5240 100644 --- a/nptl/sysdeps/pthread/pthread_cond_wait.c +++ b/nptl/sysdeps/pthread/pthread_cond_wait.c @@ -52,20 +52,14 @@ __condvar_cleanup (void *arg) appropriately. */ ++cbuffer->cond->__data.__wakeup_seq; ++cbuffer->cond->__data.__woken_seq; + ++cbuffer->cond->__data.__futex; } /* We are done. */ lll_mutex_unlock (cbuffer->cond->__data.__lock); /* Wake everybody to make sure no condvar signal gets lost. */ -#if BYTE_ORDER == LITTLE_ENDIAN - int *futex = ((int *) (&cbuffer->cond->__data.__wakeup_seq)); -#elif BYTE_ORDER == BIG_ENDIAN - int *futex = ((int *) (&cbuffer->cond->__data.__wakeup_seq)) + 1; -#else -# error "No valid byte order" -#endif - lll_futex_wake (futex, INT_MAX); + lll_futex_wake (&cbuffer->cond->__data.__futex, INT_MAX); /* Get the mutex before returning unless asynchronous cancellation is in effect. */ @@ -95,6 +89,7 @@ __pthread_cond_wait (cond, mutex) /* We have one new user of the condvar. */ ++cond->__data.__total_seq; + ++cond->__data.__futex; /* Remember the mutex we are using here. If there is already a different address store this is a bad user bug. Do not store @@ -118,27 +113,18 @@ __pthread_cond_wait (cond, mutex) /* Remember the broadcast counter. */ cbuffer.bc_seq = cond->__data.__broadcast_seq; - /* The futex syscall operates on a 32-bit word. That is fine, we - just use the low 32 bits of the sequence counter. */ -#if BYTE_ORDER == LITTLE_ENDIAN - int *futex = ((int *) (&cond->__data.__wakeup_seq)); -#elif BYTE_ORDER == BIG_ENDIAN - int *futex = ((int *) (&cond->__data.__wakeup_seq)) + 1; -#else -# error "No valid byte order" -#endif - do { + unsigned int futex_val = cond->__data.__futex; + /* Prepare to wait. Release the condvar futex. */ lll_mutex_unlock (cond->__data.__lock); /* Enable asynchronous cancellation. Required by the standard. */ cbuffer.oldtype = __pthread_enable_asynccancel (); - /* Wait until woken by signal or broadcast. Note that we - truncate the 'val' value to 32 bits. */ - lll_futex_wait (futex, (unsigned int) val); + /* Wait until woken by signal or broadcast. */ + lll_futex_wait (&cond->__data.__futex, futex_val); /* Disable asynchronous cancellation. */ __pthread_disable_asynccancel (cbuffer.oldtype); |