diff options
author | Ulrich Drepper <drepper@redhat.com> | 2003-03-18 05:31:53 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2003-03-18 05:31:53 +0000 |
commit | 4773086e0498c99ee11422fc39606e9a53f12502 (patch) | |
tree | 3fe27fef04df3b0f2fd09d99898d5e412266e86a /nptl/sysdeps | |
parent | 970269474a7a5c5fe515adc6d55aeb2a796b73dd (diff) | |
download | glibc-4773086e0498c99ee11422fc39606e9a53f12502.tar.gz glibc-4773086e0498c99ee11422fc39606e9a53f12502.tar.xz glibc-4773086e0498c99ee11422fc39606e9a53f12502.zip |
Update.
* sysdeps/unix/sysv/linux/ia64/pthread_once.c: Use __builtin_expect. Use __lll_add instead of spelling it out. Use protected symbol names. * sysdeps/unix/sysv/linux/ia64/sem_post.c: Use __builtin_expect. Use __lll_add. * sysdeps/unix/sysv/linux/ia64/lowlevellock.h (__lll_compare_and_swap): Renamed from lll_compare_and_swap. Use new name where necessary. (__lll_add): Defined. (__lll_dec_if_positive): Defined. (__lll_test_and_set): Defined. * sysdeps/ia64/pthread_spin_init.c: Removed. * sysdeps/unix/sysv/linux/ia64/lowlevelmutex.c: Removed. * sysdeps/unix/sysv/linux/ia64/sem_trywait.c: Removed. * sysdeps/unix/sysv/linux/ia64/sem_wait.c: Removed. * sysdeps/unix/sysv/linux/ia64/lowlevellock.c: Removed. * sysdeps/unix/sysv/linux/ia64/libc-lowlevellock.c: Removed. * sysdeps/unix/sysv/linux/ia64/libc-lowlevelmutex.c: Removed. * sysdeps/unix/sysv/linux/ia64/sem_timedwait.c: Removed.
Diffstat (limited to 'nptl/sysdeps')
-rw-r--r-- | nptl/sysdeps/ia64/pthread_spin_init.c | 20 | ||||
-rw-r--r-- | nptl/sysdeps/ia64/pthread_spin_unlock.c | 1 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/ia64/libc-lowlevellock.c | 19 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/ia64/libc-lowlevelmutex.c | 21 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.c | 85 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h | 118 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/ia64/lowlevelmutex.c | 100 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/ia64/pthread_once.c | 12 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/ia64/sem_post.c | 20 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/ia64/sem_timedwait.c | 92 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/ia64/sem_trywait.c | 51 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/ia64/sem_wait.c | 64 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/lowlevellock.c | 9 |
13 files changed, 86 insertions, 526 deletions
diff --git a/nptl/sysdeps/ia64/pthread_spin_init.c b/nptl/sysdeps/ia64/pthread_spin_init.c deleted file mode 100644 index c300cd442f..0000000000 --- a/nptl/sysdeps/ia64/pthread_spin_init.c +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* Not needed. pthread_spin_init is an alias for pthread_spin_unlock. */ diff --git a/nptl/sysdeps/ia64/pthread_spin_unlock.c b/nptl/sysdeps/ia64/pthread_spin_unlock.c index 90191880b7..6232764b13 100644 --- a/nptl/sysdeps/ia64/pthread_spin_unlock.c +++ b/nptl/sysdeps/ia64/pthread_spin_unlock.c @@ -26,4 +26,3 @@ pthread_spin_unlock (pthread_spinlock_t *lock) __sync_lock_release_si ((int *) lock); return 0; } -strong_alias (pthread_spin_unlock, pthread_spin_init) diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/libc-lowlevellock.c b/nptl/sysdeps/unix/sysv/linux/ia64/libc-lowlevellock.c deleted file mode 100644 index 58b4832f34..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/ia64/libc-lowlevellock.c +++ /dev/null @@ -1,19 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* Not needed. lll_mutex_* implementation is the same as lll_*. */ diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/libc-lowlevelmutex.c b/nptl/sysdeps/unix/sysv/linux/ia64/libc-lowlevelmutex.c deleted file mode 100644 index b2bf0cf862..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/ia64/libc-lowlevelmutex.c +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -/* No difference to lowlevelmutex.c */ -#include "lowlevelmutex.c" diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.c b/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.c deleted file mode 100644 index 1a1a2e1b23..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.c +++ /dev/null @@ -1,85 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <sysdep.h> -#include <lowlevellock.h> -#include <sys/time.h> - - -int -lll_unlock_wake_cb (futex) - int *futex; -{ - int oldval; - int val = *futex; - - do - oldval = val; - while ((val = lll_compare_and_swap (futex, oldval, 0)) != oldval); - if (oldval > 1) - lll_futex_wake (futex, 1); - return 0; -} -hidden_proto (lll_unlock_wake_cb) - - -int -___lll_timedwait_tid (ptid, abstime) - int *ptid; - const struct timespec *abstime; -{ - int tid; - - if (abstime == NULL || abstime->tv_nsec >= 1000000000) - return EINVAL; - - /* Repeat until thread terminated. */ - while ((tid = *ptid) != 0) - { - /* Get current time. */ - struct timeval tv; - __gettimeofday (&tv, NULL); - - /* Determine relative timeout. */ - struct timespec rt; - rt.tv_sec = abstime->tv_sec - tv.tv_sec; - rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000; - if (rt.tv_nsec < 0) - { - rt.tv_nsec += 1000000000; - rt.tv_sec--; - } - /* Already timed out? */ - if (rt.tv_sec < 0) - return ETIMEDOUT; - - /* Wait until thread terminates. */ - int err = lll_futex_timed_wait (ptid, tid, &rt); - - /* Woken due to timeout? */ - if (err == -ETIMEDOUT) - /* Yes. */ - return ETIMEDOUT; - } - - return 0; -} - -hidden_proto (___lll_timedwait_tid) diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h b/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h index b64bf1ca15..fc37e5d4fb 100644 --- a/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h +++ b/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h @@ -86,54 +86,85 @@ __r10 == -1 ? -__r8 : __r8; \ }) -#define lll_compare_and_swap(futex, oldval, newval) \ +#define __lll_compare_and_swap(futex, oldval, newval) \ __sync_val_compare_and_swap_si ((futex), (oldval), (newval)) +/* Add inc to *futex atomically and return the old value. */ +#define __lll_add(futex, inc) \ + ({ \ + int __val, __oldval; \ + int *__futex = (futex); \ + int __inc = inc; \ + \ + __val = *__futex; \ + do \ + { \ + __oldval = __val; \ + __val = __lll_compare_and_swap (__futex, __oldval, __oldval + __inc); \ + } \ + while (__builtin_expect (__val != __oldval, 0)); \ + __val; \ + }) + +/* Decrement *futex if it is > 0, and return the old value. */ +#define __lll_dec_if_positive(futex) \ + ({ \ + int __val, __oldval; \ + int *__futex = (futex); \ + \ + __val = *__futex; \ + do \ + { \ + if (__builtin_expect (__val <= 0, 0)) \ + break; \ + __oldval = __val; \ + __val = __lll_compare_and_swap (__futex, __oldval, __oldval - 1); \ + } \ + while (__builtin_expect (__val != __oldval, 0)); \ + __val; \ + }) + +/* Atomically store newval and return the old value. */ +#define __lll_test_and_set(futex, newval) \ + __sync_lock_test_and_set_si ((futex), (newval)) + static inline int __attribute__ ((always_inline)) __lll_mutex_trylock (int *futex) { - return lll_compare_and_swap (futex, 0, 1) != 0; + return __lll_compare_and_swap (futex, 0, 1) != 0; } #define lll_mutex_trylock(futex) __lll_mutex_trylock (&(futex)) -extern void ___lll_mutex_lock (int *, int) attribute_hidden; +extern void __lll_lock_wait (int *futex, int val) attribute_hidden; static inline void __attribute__ ((always_inline)) __lll_mutex_lock (int *futex) { - int oldval; - int val = *futex; - - do - oldval = val; - while ((val = lll_compare_and_swap (futex, oldval, oldval + 1)) != oldval); - if (oldval > 0) - ___lll_mutex_lock (futex, oldval + 1); + int val = __lll_add (futex, 1); + + if (__builtin_expect (val != 0, 0)) + __lll_lock_wait (futex, val); } #define lll_mutex_lock(futex) __lll_mutex_lock (&(futex)) -extern int ___lll_mutex_timedlock (int *, const struct timespec *, int) - attribute_hidden; +extern int __lll_timedlock_wait (int *futex, int val, const struct timespec *) + attribute_hidden; static inline int __attribute__ ((always_inline)) __lll_mutex_timedlock (int *futex, const struct timespec *abstime) { - int oldval; - int val = *futex; + int val = __lll_add (futex, 1); int result = 0; - do - oldval = val; - while ((val = lll_compare_and_swap (futex, oldval, oldval + 1)) != oldval); - if (oldval > 0) - result = ___lll_mutex_timedlock (futex, abstime, oldval + 1); + if (__builtin_expect (val != 0, 0)) + result = __lll_timedlock_wait (futex, val, abstime); return result; } @@ -145,13 +176,9 @@ static inline void __attribute__ ((always_inline)) __lll_mutex_unlock (int *futex) { - int oldval; - int val = *futex; + int val = __lll_test_and_set (futex, 0); - do - oldval = val; - while ((val = lll_compare_and_swap (futex, oldval, 0)) != oldval); - if (oldval > 1) + if (__builtin_expect (val > 1, 0)) lll_futex_wake (futex, 1); } #define lll_mutex_unlock(futex) __lll_mutex_unlock(&(futex)) @@ -182,30 +209,25 @@ extern int lll_unlock_wake_cb (int *__futex) attribute_hidden; wakeup when the clone terminates. The memory location contains the thread ID while the clone is running and is reset to zero afterwards. */ -static inline void -__attribute__ ((always_inline)) -__lll_wait_tid (int *ptid) -{ - int tid; - - while ((tid = *ptid) != 0) - lll_futex_wait (ptid, tid); -} -#define lll_wait_tid(tid) __lll_wait_tid(&(tid)) - - -extern int ___lll_timedwait_tid (int *, const struct timespec *) +#define lll_wait_tid(tid) \ + do \ + { \ + __typeof (tid) __tid; \ + while ((__tid = (tid)) != 0) \ + lll_futex_wait (&(tid), __tid); \ + } \ + while (0) + +extern int __lll_timedwait_tid (int *, const struct timespec *) attribute_hidden; -static inline int -__attribute__ ((always_inline)) -__lll_timedwait_tid (int *ptid, const struct timespec *abstime) -{ - if (*ptid == 0) - return 0; - return ___lll_timedwait_tid (ptid, abstime); -} -#define lll_timedwait_tid(tid, abstime) __lll_timedwait_tid (&(tid), abstime) +#define lll_timedwait_tid(tid, abstime) \ + ({ \ + int __res = 0; \ + if ((tid) != 0) \ + __res = __lll_timedwait_tid (&(tid), (abstime)); \ + __res; \ + }) /* Conditional variable handling. */ diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/lowlevelmutex.c b/nptl/sysdeps/unix/sysv/linux/ia64/lowlevelmutex.c deleted file mode 100644 index bf6f5f3846..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/ia64/lowlevelmutex.c +++ /dev/null @@ -1,100 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <sysdep.h> -#include <lowlevellock.h> -#include <sys/time.h> - - -void -___lll_mutex_lock (futex, newval) - int *futex; - int newval; -{ - int oldval, val; - - do - { - lll_futex_wait (futex, newval); - val = *futex; - do - oldval = val; - while ((val = lll_compare_and_swap (futex, oldval, oldval + 1)) - != oldval); - newval = val + 1; - } - while (val != 0); - - *futex = 2; -} -hidden_proto (___lll_mutex_lock) - - -int -___lll_mutex_timedlock (futex, abstime, newval) - int *futex; - const struct timespec *abstime; - int newval; -{ - /* Reject invalid timeouts. */ - if (abstime->tv_nsec >= 1000000000) - return EINVAL; - - int oldval, val; - do - { - /* Get the current time. */ - struct timeval tv; - __gettimeofday (&tv, NULL); - - /* Compute relative timeout. */ - struct timespec rt; - rt.tv_sec = abstime->tv_sec - tv.tv_sec; - rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000; - if (rt.tv_nsec < 0) - { - rt.tv_nsec += 1000000000; - --rt.tv_sec; - } - /* Already timed out? */ - if (rt.tv_sec < 0) - return ETIMEDOUT; - - /* Wait. */ - int err = lll_futex_timed_wait (futex, newval, &rt); - - /* If timed out return with an appropriate error. */ - if (err == -ETIMEDOUT) - return ETIMEDOUT; - - val = *futex; - do - oldval = val; - while ((val = lll_compare_and_swap (futex, oldval, oldval + 1)) - != oldval); - newval = val + 1; - } - while (val != 0); - - *futex = 2; - - return 0; -} -hidden_proto (___lll_mutex_timedlock) diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/pthread_once.c b/nptl/sysdeps/unix/sysv/linux/ia64/pthread_once.c index e5cb6132d9..2f671fac41 100644 --- a/nptl/sysdeps/unix/sysv/linux/ia64/pthread_once.c +++ b/nptl/sysdeps/unix/sysv/linux/ia64/pthread_once.c @@ -52,10 +52,10 @@ __pthread_once (once_control, init_routine) oldval = val; newval = (oldval & 3) | __fork_generation | 1; + val = __lll_compare_and_swap (once_control, oldval, newval); } - while ((val = lll_compare_and_swap (once_control, oldval, newval)) - != oldval); - + while (__builtin_expect (val != oldval, 0)); + /* Check if another thread already runs the initializer. */ if ((oldval & 1) != 0) { @@ -80,11 +80,7 @@ __pthread_once (once_control, init_routine) /* Add one to *once_control. */ - val = *once_control; - do - oldval = val; - while ((val = lll_compare_and_swap (once_control, oldval, oldval + 1)) - != oldval); + __lll_add (once_control, 1); /* Wake up all other threads. */ lll_futex_wake (once_control, INT_MAX); diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/sem_post.c b/nptl/sysdeps/unix/sysv/linux/ia64/sem_post.c index 32dba265a9..9b5049e7ae 100644 --- a/nptl/sysdeps/unix/sysv/linux/ia64/sem_post.c +++ b/nptl/sysdeps/unix/sysv/linux/ia64/sem_post.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. +/* sem_post -- post to a POSIX semaphore. IA-64 version. + Copyright (C) 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. @@ -25,20 +26,15 @@ #include <shlib-compat.h> - int __new_sem_post (sem_t *sem) { - int oldval, val; - int err; + int *futex = (int *) sem; + int err, nr; - val = *(int *) sem; - do - oldval = val; - while ((val = lll_compare_and_swap ((int *) sem, oldval, oldval + 1)) - != oldval); - err = lll_futex_wake ((int *) sem, oldval + 1); - if (err < 0) + nr = __lll_add (futex, 1); + err = lll_futex_wake (futex, nr + 1); + if (__builtin_expect (err, 0) < 0) { __set_errno (-err); return -1; @@ -46,7 +42,7 @@ __new_sem_post (sem_t *sem) return 0; } versioned_symbol (libpthread, __new_sem_post, sem_post, GLIBC_2_1); -#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1) +#if SHLIB_COMPAT (libpthread, GLIBC_2_0, GLIBC_2_1) strong_alias (__new_sem_post, __old_sem_post) compat_symbol (libpthread, __old_sem_post, sem_post, GLIBC_2_0); #endif diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/sem_timedwait.c b/nptl/sysdeps/unix/sysv/linux/ia64/sem_timedwait.c deleted file mode 100644 index 881e6e20f7..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/ia64/sem_timedwait.c +++ /dev/null @@ -1,92 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <sysdep.h> -#include <lowlevellock.h> -#include <internaltypes.h> -#include <semaphore.h> - -#include <shlib-compat.h> - - -int -sem_timedwait (sem, abstime) - sem_t *sem; - const struct timespec *abstime; -{ - int oldval, val; - - val = *(int *) sem; - do - { - while (__builtin_expect (val == 0, 0)) - { - /* Check for invalid timeout values. */ - if (abstime->tv_nsec >= 1000000000) - { - __set_errno (EINVAL); - return -1; - } - - /* Get the current time. */ - struct timeval tv; - (void) __gettimeofday(&tv, NULL); - - /* Compute the relative timeout. */ - struct timespec rt; - rt.tv_sec = abstime->tv_sec - tv.tv_sec; - rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000; - if (rt.tv_nsec < 0) - { - rt.tv_nsec += 1000000000; - --rt.tv_sec; - } - /* Already timed out. */ - if (rt.tv_sec < 0) - { - __set_errno (ETIMEDOUT); - return -1; - } - - /* Do wait. */ - int err = lll_futex_timed_wait ((int *) sem, 0, &rt); - - /* Returned after timing out? */ - if (err == -ETIMEDOUT) - { - __set_errno (ETIMEDOUT); - return -1; - } - - /* Handle EINTR. */ - if (err != 0 && err != -EWOULDBLOCK) - { - __set_errno (-err); - return -1; - } - - val = *(int *) sem; - } - oldval = val; - } - while ((val = lll_compare_and_swap ((int *) sem, oldval, oldval - 1)) - != oldval); - return 0; -} diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/sem_trywait.c b/nptl/sysdeps/unix/sysv/linux/ia64/sem_trywait.c deleted file mode 100644 index 25127c21a1..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/ia64/sem_trywait.c +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <sysdep.h> -#include <lowlevellock.h> -#include <internaltypes.h> -#include <semaphore.h> - -#include <shlib-compat.h> - - -int -__new_sem_trywait (sem_t *sem) -{ - int oldval, val = *(int *) sem; - - do - { - if (__builtin_expect (val == 0, 0)) - { - __set_errno (EAGAIN); - return -1; - } - oldval = val; - } - while ((val = lll_compare_and_swap ((int *) sem, oldval, oldval - 1)) - != oldval); - return 0; -} -versioned_symbol (libpthread, __new_sem_trywait, sem_trywait, GLIBC_2_1); -#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1) -strong_alias (__new_sem_trywait, __old_sem_trywait) -compat_symbol (libpthread, __old_sem_trywait, sem_trywait, GLIBC_2_0); -#endif diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/sem_wait.c b/nptl/sysdeps/unix/sysv/linux/ia64/sem_wait.c deleted file mode 100644 index 958159f2d5..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/ia64/sem_wait.c +++ /dev/null @@ -1,64 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jakub Jelinek <jakub@redhat.com>, 2003. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include <errno.h> -#include <sysdep.h> -#include <lowlevellock.h> -#include <internaltypes.h> -#include <semaphore.h> - -#include <shlib-compat.h> - - -int -__new_sem_wait (sem_t *sem) -{ - int oldval, val; - - /* Atomically decrement semaphore counter if it is > 0. */ - val = *(int *) sem; - do - { - while (__builtin_expect (val == 0, 0)) - { - /* Do wait. */ - int err = lll_futex_wait ((int *) sem, 0); - - /* Handle EINTR. */ - if (err != 0 && err != -EWOULDBLOCK) - { - __set_errno (-err); - return -1; - } - - val = *(int *) sem; - } - oldval = val; - } - while ((val = lll_compare_and_swap ((int *) sem, oldval, oldval - 1)) - != oldval); - - return 0; -} - -versioned_symbol (libpthread, __new_sem_wait, sem_wait, GLIBC_2_1); -#if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1) -strong_alias (__new_sem_wait, __old_sem_wait) -compat_symbol (libpthread, __old_sem_wait, sem_wait, GLIBC_2_0); -#endif diff --git a/nptl/sysdeps/unix/sysv/linux/lowlevellock.c b/nptl/sysdeps/unix/sysv/linux/lowlevellock.c index cdde262384..49d68da702 100644 --- a/nptl/sysdeps/unix/sysv/linux/lowlevellock.c +++ b/nptl/sysdeps/unix/sysv/linux/lowlevellock.c @@ -83,11 +83,10 @@ hidden_proto (__lll_timedlock_wait) int lll_unlock_wake_cb (int *futex) { - if (__lll_add (futex, -1) - 1 != 0) - { - *futex = 0; - lll_futex_wake (futex, 1); - } + int val = __lll_test_and_set (futex, 0); + + if (__builtin_expect (val > 1, 0)) + lll_futex_wake (futex, 1); return 0; } |