diff options
author | Ulrich Drepper <drepper@redhat.com> | 2003-09-22 21:30:25 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2003-09-22 21:30:25 +0000 |
commit | 39358e8b2bbf78b3ee50027abcd12837473b5f9f (patch) | |
tree | c579eb3fe367bd09bf4c07e9dfa6060c1f3bb79c | |
parent | c0df57e1ce270466be342d9998f72633764b22dc (diff) | |
download | glibc-39358e8b2bbf78b3ee50027abcd12837473b5f9f.tar.gz glibc-39358e8b2bbf78b3ee50027abcd12837473b5f9f.tar.xz glibc-39358e8b2bbf78b3ee50027abcd12837473b5f9f.zip |
Update.
2003-09-22 Jakub Jelinek <jakub@redhat.com> * sysdeps/unix/sysv/linux/lowlevellock.c (__lll_timedlock_wait): Use lll_futex_timed_wait instead of lll_futex_wait. * sysdeps/unix/sysv/linux/s390/lowlevellock.c: Removed. * sysdeps/unix/sysv/linux/s390/lowlevelmutex.c: Removed. * sysdeps/unix/sysv/linux/s390/libc-lowlevellock.c: Removed. * sysdeps/unix/sysv/linux/s390/libc-lowlevelmutex.c: Removed. * sysdeps/unix/sysv/linux/s390/sem_trywait.c: Removed. * sysdeps/unix/sysv/linux/s390/sem_wait.c: Removed. * sysdeps/unix/sysv/linux/s390/sem_post.c: Removed. * sysdeps/unix/sysv/linux/s390/sem_timedwait.c: Removed. * sysdeps/unix/sysv/linux/s390/lowlevellock.h: Include atomic.h. Completely revamp the locking macros. No distinction between normal and mutex locking anymore. * sysdeps/unix/sysv/linux/sparc/lowlevellock.h: Likewise. * sysdeps/unix/sysv/linux/ia64/lowlevellock.h (__lll_lock_wait, __lll_lock_timedwait): Fix prototypes. * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h (__lll_lock_wait, __lll_lock_timedwait): Likewise. (lll_mutex_lock, lll_mutex_cond_lock): Use _val instead of _bool macros, add __builtin_expect. (lll_mutex_timedlock): Likewise. Fix return value. * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevelmutex.S: Removed. * sysdeps/unix/sysv/linux/i386/i586/libc-lowlevelmutex.S: Removed. * sysdeps/unix/sysv/linux/i386/i586/lowlevelmutex.S: Removed. * sysdeps/unix/sysv/linux/i386/i686/libc-lowlevelmutex.S: Removed. * sysdeps/unix/sysv/linux/i386/i686/lowlevelmutex.S: Removed. * sysdeps/unix/sysv/linux/x86_64/libc-lowlevelmutex.S: Removed. * sysdeps/unix/sysv/linux/lowlevelmutex.c: Removed. * sysdeps/unix/sysv/linux/libc-lowlevelmutex.c: Removed.
24 files changed, 86 insertions, 737 deletions
diff --git a/include/atomic.h b/include/atomic.h index 299f196e25..092b6e00a3 100644 --- a/include/atomic.h +++ b/include/atomic.h @@ -71,8 +71,8 @@ #ifndef atomic_compare_and_exchange_val_rel -# define atomic_compare_and_exchange_val_rel(mem, oldval, newval) \ - atomic_compare_and_exchange_val_acq (mem, oldval, newval) +# define atomic_compare_and_exchange_val_rel(mem, newval, oldval) \ + atomic_compare_and_exchange_val_acq (mem, newval, oldval) #endif @@ -95,8 +95,8 @@ #ifndef atomic_compare_and_exchange_bool_rel -# define atomic_compare_and_exchange_bool_rel(mem, oldval, newval) \ - atomic_compare_and_exchange_bool_acq (mem, oldval, newval) +# define atomic_compare_and_exchange_bool_rel(mem, newval, oldval) \ + atomic_compare_and_exchange_bool_acq (mem, newval, oldval) #endif diff --git a/nptl/ChangeLog b/nptl/ChangeLog index e74dec5c36..eb32fe193e 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,35 @@ +2003-09-22 Jakub Jelinek <jakub@redhat.com> + + * sysdeps/unix/sysv/linux/lowlevellock.c (__lll_timedlock_wait): Use + lll_futex_timed_wait instead of lll_futex_wait. + * sysdeps/unix/sysv/linux/s390/lowlevellock.c: Removed. + * sysdeps/unix/sysv/linux/s390/lowlevelmutex.c: Removed. + * sysdeps/unix/sysv/linux/s390/libc-lowlevellock.c: Removed. + * sysdeps/unix/sysv/linux/s390/libc-lowlevelmutex.c: Removed. + * sysdeps/unix/sysv/linux/s390/sem_trywait.c: Removed. + * sysdeps/unix/sysv/linux/s390/sem_wait.c: Removed. + * sysdeps/unix/sysv/linux/s390/sem_post.c: Removed. + * sysdeps/unix/sysv/linux/s390/sem_timedwait.c: Removed. + * sysdeps/unix/sysv/linux/s390/lowlevellock.h: Include atomic.h. + Completely revamp the locking macros. No distinction between + normal and mutex locking anymore. + * sysdeps/unix/sysv/linux/sparc/lowlevellock.h: Likewise. + * sysdeps/unix/sysv/linux/ia64/lowlevellock.h (__lll_lock_wait, + __lll_lock_timedwait): Fix prototypes. + * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h (__lll_lock_wait, + __lll_lock_timedwait): Likewise. + (lll_mutex_lock, lll_mutex_cond_lock): Use _val instead of _bool + macros, add __builtin_expect. + (lll_mutex_timedlock): Likewise. Fix return value. + * sysdeps/unix/sysv/linux/i386/i486/libc-lowlevelmutex.S: Removed. + * sysdeps/unix/sysv/linux/i386/i586/libc-lowlevelmutex.S: Removed. + * sysdeps/unix/sysv/linux/i386/i586/lowlevelmutex.S: Removed. + * sysdeps/unix/sysv/linux/i386/i686/libc-lowlevelmutex.S: Removed. + * sysdeps/unix/sysv/linux/i386/i686/lowlevelmutex.S: Removed. + * sysdeps/unix/sysv/linux/x86_64/libc-lowlevelmutex.S: Removed. + * sysdeps/unix/sysv/linux/lowlevelmutex.c: Removed. + * sysdeps/unix/sysv/linux/libc-lowlevelmutex.c: Removed. + 2003-09-22 Ulrich Drepper <drepper@redhat.com> * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i486/libc-lowlevelmutex.S b/nptl/sysdeps/unix/sysv/linux/i386/i486/libc-lowlevelmutex.S deleted file mode 100644 index 8b6bff4761..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/i386/i486/libc-lowlevelmutex.S +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 2002, 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. - - 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. */ - -/* In libc.so we do not unconditionally use the lock prefix. Only if - the application is using threads. */ -#ifndef UP -# define LOCK \ - cmpl $0, %gs:MULTIPLE_THREADS_OFFSET; \ - je,pt 0f; \ - lock; \ -0: -#endif - -#include "lowlevelmutex.S" diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i586/libc-lowlevelmutex.S b/nptl/sysdeps/unix/sysv/linux/i386/i586/libc-lowlevelmutex.S deleted file mode 100644 index 7c24ed1d3c..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/i386/i586/libc-lowlevelmutex.S +++ /dev/null @@ -1 +0,0 @@ -#include "../i486/libc-lowlevelmutex.S" diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i586/lowlevelmutex.S b/nptl/sysdeps/unix/sysv/linux/i386/i586/lowlevelmutex.S deleted file mode 100644 index 50481991ff..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/i386/i586/lowlevelmutex.S +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (C) 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. - - 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 "../i486/lowlevelmutex.S" diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i686/libc-lowlevelmutex.S b/nptl/sysdeps/unix/sysv/linux/i386/i686/libc-lowlevelmutex.S deleted file mode 100644 index 7c24ed1d3c..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/i386/i686/libc-lowlevelmutex.S +++ /dev/null @@ -1 +0,0 @@ -#include "../i486/libc-lowlevelmutex.S" diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i686/lowlevelmutex.S b/nptl/sysdeps/unix/sysv/linux/i386/i686/lowlevelmutex.S deleted file mode 100644 index 50481991ff..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/i386/i686/lowlevelmutex.S +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (C) 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. - - 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 "../i486/lowlevelmutex.S" diff --git a/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h b/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h index b30659fe90..d068b06894 100644 --- a/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h +++ b/nptl/sysdeps/unix/sysv/linux/ia64/lowlevellock.h @@ -120,7 +120,7 @@ __lll_mutex_trylock (int *futex) #define lll_mutex_trylock(futex) __lll_mutex_trylock (&(futex)) -extern void __lll_lock_wait (int *futex, int val) attribute_hidden; +extern void __lll_lock_wait (int *futex) attribute_hidden; static inline void @@ -143,7 +143,7 @@ __lll_mutex_cond_lock (int *futex) #define lll_mutex_cond_lock(futex) __lll_mutex_cond_lock (&(futex)) -extern int __lll_timedlock_wait (int *futex, int val, const struct timespec *) +extern int __lll_timedlock_wait (int *futex, const struct timespec *) attribute_hidden; diff --git a/nptl/sysdeps/unix/sysv/linux/libc-lowlevelmutex.c b/nptl/sysdeps/unix/sysv/linux/libc-lowlevelmutex.c deleted file mode 100644 index 7c594e3470..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/libc-lowlevelmutex.c +++ /dev/null @@ -1 +0,0 @@ -/* Nothing needed here in fact. */ diff --git a/nptl/sysdeps/unix/sysv/linux/lowlevellock.c b/nptl/sysdeps/unix/sysv/linux/lowlevellock.c index 5021cdf4ba..932e27300f 100644 --- a/nptl/sysdeps/unix/sysv/linux/lowlevellock.c +++ b/nptl/sysdeps/unix/sysv/linux/lowlevellock.c @@ -68,7 +68,7 @@ __lll_timedlock_wait (int *futex, const struct timespec *abstime) /* Wait. */ int oldval = atomic_compare_and_exchange_val_acq (futex, 2, 1); if (oldval != 0) - lll_futex_wait (futex, 2); + lll_futex_timed_wait (futex, 2, &rt); } while (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0); diff --git a/nptl/sysdeps/unix/sysv/linux/lowlevelmutex.c b/nptl/sysdeps/unix/sysv/linux/lowlevelmutex.c deleted file mode 100644 index 7c594e3470..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/lowlevelmutex.c +++ /dev/null @@ -1 +0,0 @@ -/* Nothing needed here in fact. */ diff --git a/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h b/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h index 0caee0cd1f..a715879dbd 100644 --- a/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h +++ b/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h @@ -101,30 +101,35 @@ #define lll_mutex_trylock(lock) __lll_trylock (&(lock)) -extern void __lll_lock_wait (int *futex, int val) attribute_hidden; +extern void __lll_lock_wait (int *futex) attribute_hidden; #define lll_mutex_lock(lock) \ (void) ({ \ int *__futex = &(lock); \ - if (atomic_compare_and_exchange_bool_acq (__futex, 1, 0) != 0) \ + if (__builtin_expect (atomic_compare_and_exchange_val_acq (__futex, 1, 0),\ + 0) != 0) \ __lll_lock_wait (__futex); \ }) #define lll_mutex_cond_lock(lock) \ (void) ({ \ int *__futex = &(lock); \ - if (atomic_compare_and_exchange_bool_acq (__futex, 2, 0) != 0) \ + if (__builtin_expect (atomic_compare_and_exchange_val_acq (__futex, 2, 0),\ + 0) != 0) \ __lll_lock_wait (__futex); \ }) extern int __lll_timedlock_wait - (int *futex, int val, const struct timespec *) attribute_hidden; + (int *futex, const struct timespec *) attribute_hidden; #define lll_mutex_timedlock(lock, abstime) \ - (void) ({ \ + ({ \ int *__futex = &(lock); \ - if (atomic_compare_and_exchange_bool_acq (__futex, 1, 0) != 0) \ - __lll_timedlock_wait (__futex, abstime); \ + int __val = 0; \ + if (__builtin_expect (atomic_compare_and_exchange_val_acq (__futex, 1, 0),\ + 0) != 0) \ + __val = __lll_timedlock_wait (__futex, abstime); \ + __val; \ }) #define lll_mutex_unlock(lock) \ diff --git a/nptl/sysdeps/unix/sysv/linux/s390/libc-lowlevellock.c b/nptl/sysdeps/unix/sysv/linux/s390/libc-lowlevellock.c deleted file mode 100644 index 085ee30188..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/s390/libc-lowlevellock.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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_lock (futex, newval) - int *futex; - int newval; -{ - do - { - int oldval; - - lll_futex_wait (futex, newval); - lll_compare_and_swap (futex, oldval, newval, "lr %2,%1; ahi %2,-1"); - } - while (newval != 0); - - *futex = -1; -} diff --git a/nptl/sysdeps/unix/sysv/linux/s390/libc-lowlevelmutex.c b/nptl/sysdeps/unix/sysv/linux/s390/libc-lowlevelmutex.c deleted file mode 100644 index 38f11ba3a5..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/s390/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 Martin Schwidefsky <schwidefsky@de.ibm.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/s390/lowlevellock.c b/nptl/sysdeps/unix/sysv/linux/s390/lowlevellock.c deleted file mode 100644 index 37d885760d..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/s390/lowlevellock.c +++ /dev/null @@ -1,99 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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_lock (futex, newval) - int *futex; - int newval; -{ - do - { - int oldval; - - lll_futex_wait (futex, newval); - lll_compare_and_swap (futex, oldval, newval, "lr %2,%1; ahi %2,-1"); - } - while (newval != 0); - - *futex = -1; -} - - -int -lll_unlock_wake_cb (futex) - int *futex; -{ - int oldval; - int newval; - - lll_compare_and_swap (futex, oldval, newval, "lr %2,%1; ahi %2,1"); - if (oldval < 0) - lll_futex_wake (futex, 1); - return 0; -} - - -int -___lll_timedwait_tid (ptid, abstime) - int *ptid; - const struct timespec *abstime; -{ - int tid; - - if (abstime->tv_nsec < 0 || 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; -} - diff --git a/nptl/sysdeps/unix/sysv/linux/s390/lowlevellock.h b/nptl/sysdeps/unix/sysv/linux/s390/lowlevellock.h index a51826ab84..5751206dd9 100644 --- a/nptl/sysdeps/unix/sysv/linux/s390/lowlevellock.h +++ b/nptl/sysdeps/unix/sysv/linux/s390/lowlevellock.h @@ -23,6 +23,7 @@ #include <time.h> #include <sys/param.h> #include <bits/pthreadtypes.h> +#include <atomic.h> #define SYS_futex 238 #define FUTEX_WAIT 0 @@ -126,19 +127,14 @@ __lll_mutex_trylock (int *futex) #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) attribute_hidden; static inline void __attribute__ ((always_inline)) __lll_mutex_lock (int *futex) { - int oldval; - int newval; - - lll_compare_and_swap (futex, oldval, newval, "lr %2,%1; ahi %2,1"); - if (oldval > 0) - ___lll_mutex_lock (futex, newval); + if (atomic_compare_and_exchange_bool_acq (futex, 1, 0) != 0) + __lll_lock_wait (futex); } #define lll_mutex_lock(futex) __lll_mutex_lock (&(futex)) @@ -146,32 +142,21 @@ static inline void __attribute__ ((always_inline)) __lll_mutex_cond_lock (int *futex) { - int oldval; - int newval; - - lll_compare_and_swap (futex, oldval, newval, "lr %2,%1; ahi %2,2"); - if (oldval > 0) - ___lll_mutex_lock (futex, newval); + if (atomic_compare_and_exchange_bool_acq (futex, 2, 0) != 0) + __lll_lock_wait (futex); } #define lll_mutex_cond_lock(futex) __lll_mutex_cond_lock (&(futex)) - -extern int ___lll_mutex_timedlock (int *, const struct timespec *, int) - attribute_hidden; - +extern int __lll_timedlock_wait + (int *futex, const struct timespec *) attribute_hidden; static inline int __attribute__ ((always_inline)) __lll_mutex_timedlock (int *futex, const struct timespec *abstime) { - int oldval; - int newval; int result = 0; - - lll_compare_and_swap (futex, oldval, newval, "lr %2,%1; ahi %2,1"); - if (oldval > 0) - result = ___lll_mutex_timedlock (futex, abstime, newval); - + if (atomic_compare_and_exchange_bool_acq (futex, 1, 0) != 0) + result = __lll_timedlock_wait (futex, abstime); return result; } #define lll_mutex_timedlock(futex, abstime) \ @@ -208,15 +193,19 @@ __lll_mutex_unlock_force (int *futex) /* We have a separate internal lock implementation which is not tied - to binary compatibility. */ + to binary compatibility. We can use the lll_mutex_*. */ /* Type for lock object. */ typedef int lll_lock_t; /* Initializers for lock. */ -#define LLL_LOCK_INITIALIZER (1) -#define LLL_LOCK_INITIALIZER_LOCKED (0) +#define LLL_LOCK_INITIALIZER (0) +#define LLL_LOCK_INITIALIZER_LOCKED (1) +#define lll_trylock(futex) lll_mutex_trylock (futex) +#define lll_lock(futex) lll_mutex_lock (futex) +#define lll_unlock(futex) lll_mutex_unlock (futex) +#define lll_islocked(futex) lll_mutex_islocked (futex) extern int lll_unlock_wake_cb (int *__futex) attribute_hidden; @@ -226,54 +215,6 @@ extern int lll_unlock_wake_cb (int *__futex) attribute_hidden; <0 - taken by more users */ -static inline int -__attribute__ ((always_inline)) -__lll_trylock (int *futex) -{ - unsigned int old; - - __asm __volatile ("cs %0,%3,%1" - : "=d" (old), "=Q" (*futex) - : "0" (1), "d" (0), "m" (*futex) : "cc" ); - return old != 1; -} -#define lll_trylock(futex) __lll_trylock (&(futex)) - - -extern void ___lll_lock (int *, int) attribute_hidden; - -static inline void -__attribute__ ((always_inline)) -__lll_lock (int *futex) -{ - int oldval; - int newval; - - lll_compare_and_swap (futex, oldval, newval, "lr %2,%1; ahi %2,-1"); - if (newval < 0) - ___lll_lock (futex, newval); -} -#define lll_lock(futex) __lll_lock (&(futex)) - - -static inline void -__attribute__ ((always_inline)) -__lll_unlock (int *futex) -{ - int oldval; - int newval; - - lll_compare_and_swap (futex, oldval, newval, "lhi %2,1"); - if (oldval < 0) - lll_futex_wake (futex, 1); -} -#define lll_unlock(futex) __lll_unlock(&(futex)) - - -#define lll_islocked(futex) \ - (futex != 1) - - /* The kernel notifies a process with uses CLONE_CLEARTID via futex wakeup when the clone terminates. The memory location contains the thread ID while the clone is running and is reset to zero @@ -289,20 +230,16 @@ __lll_wait_tid (int *ptid) } #define lll_wait_tid(tid) __lll_wait_tid(&(tid)) - -extern int ___lll_timedwait_tid (int *, const struct timespec *) +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/s390/lowlevelmutex.c b/nptl/sysdeps/unix/sysv/linux/s390/lowlevelmutex.c deleted file mode 100644 index d61ebf95e6..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/s390/lowlevelmutex.c +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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> - - -void -___lll_mutex_lock (futex, newval) - int *futex; - int newval; -{ - int oldval; - - do - { - lll_futex_wait (futex, newval); - lll_compare_and_swap (futex, oldval, newval, "lr %2,%1; ahi %2,1"); - } - while (oldval != 0); - - *futex = 2; -} - - -int -___lll_mutex_timedlock (futex, abstime, newval) - int *futex; - const struct timespec *abstime; - int newval; -{ - /* Reject invalid timeouts. */ - if (abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) - return EINVAL; - - int oldval; - 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; - - /* XXX oldval in undefined !!! */ - lll_compare_and_swap (futex, oldval, newval, "lr %2,%1; ahi %2,1"); - } - while (oldval != 0); - - *futex = 2; - - return 0; -} diff --git a/nptl/sysdeps/unix/sysv/linux/s390/sem_post.c b/nptl/sysdeps/unix/sysv/linux/s390/sem_post.c deleted file mode 100644 index b36ebdbceb..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/s390/sem_post.c +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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_post (sem_t *sem) -{ - int oldval; - int newval; - int err; - - lll_compare_and_swap ((int *) sem, oldval, newval, "lr %2,%1; ahi %2,1"); - err = lll_futex_wake ((int *) sem, newval); - if (err < 0) - { - __set_errno (-err); - return -1; - } - return 0; -} -versioned_symbol (libpthread, __new_sem_post, sem_post, 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/s390/sem_timedwait.c b/nptl/sysdeps/unix/sysv/linux/s390/sem_timedwait.c deleted file mode 100644 index b1c57beff9..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/s390/sem_timedwait.c +++ /dev/null @@ -1,99 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <pthreadP.h> -#include <shlib-compat.h> - - -int -sem_timedwait (sem, abstime) - sem_t *sem; - const struct timespec *abstime; -{ - /* First check for cancellation. */ - CANCELLATION_P (THREAD_SELF); - - int *futex = (int *) sem; - int oldval; - int newval; - int err; - - do - { - /* Atomically decrement semaphore counter if it is > 0. */ - lll_compare_and_swap (futex, oldval, newval, - "ltr %2,%1; jnp 1f; ahi %2,-1"); - /* oldval != newval if the semaphore count has been decremented. */ - if (oldval != newval) - return 0; - - /* Check for invalid timeout values. */ - if (abstime->tv_nsec < 0 || 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; - } - - /* Enable asynchronous cancellation. Required by the standard. */ - int oldtype = __pthread_enable_asynccancel (); - - /* Do wait. */ - err = lll_futex_timed_wait (futex, 0, &rt); - - /* Disable asynchronous cancellation. */ - __pthread_disable_asynccancel (oldtype); - - /* Returned after timing out? */ - if (err == -ETIMEDOUT) - { - __set_errno (ETIMEDOUT); - return -1; - } - } - while (err == 0 || err == -EWOULDBLOCK); - - __set_errno (-err); - return -1; -} diff --git a/nptl/sysdeps/unix/sysv/linux/s390/sem_trywait.c b/nptl/sysdeps/unix/sysv/linux/s390/sem_trywait.c deleted file mode 100644 index 3695ccddfd..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/s390/sem_trywait.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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; - int newval; - - /* Atomically decrement sem counter if it is > 0. */ - lll_compare_and_swap ((int *) sem, oldval, newval, - "ltr %2,%1; jnp 1f; ahi %2,-1"); - /* oldval != newval if the semaphore count has been decremented. */ - if (oldval == newval) - { - __set_errno (EAGAIN); - return -1; - } - 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/s390/sem_wait.c b/nptl/sysdeps/unix/sysv/linux/s390/sem_wait.c deleted file mode 100644 index 2be1dbbac4..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/s390/sem_wait.c +++ /dev/null @@ -1,71 +0,0 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Martin Schwidefsky <schwidefsky@de.ibm.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 <pthreadP.h> -#include <shlib-compat.h> - - -int -__new_sem_wait (sem_t *sem) -{ - /* First check for cancellation. */ - CANCELLATION_P (THREAD_SELF); - - int *futex = (int *) sem; - int err; - - do - { - int oldval; - int newval; - - /* Atomically decrement semaphore counter if it is > 0. */ - lll_compare_and_swap (futex, oldval, newval, - "ltr %2,%1; jnp 1f; ahi %2,-1"); - - /* oldval != newval if the semaphore count has been decremented. */ - if (oldval != newval) - return 0; - - /* Enable asynchronous cancellation. Required by the standard. */ - int oldtype = __pthread_enable_asynccancel (); - - /* Do wait. */ - err = lll_futex_wait (futex, 0); - - /* Disable asynchronous cancellation. */ - __pthread_disable_asynccancel (oldtype); - } - while (err == 0 || err == -EWOULDBLOCK); - - __set_errno (-err); - return -1; -} - -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/sparc/lowlevellock.h b/nptl/sysdeps/unix/sysv/linux/sparc/lowlevellock.h index e8c3ebeedf..76ec431a6c 100644 --- a/nptl/sysdeps/unix/sysv/linux/sparc/lowlevellock.h +++ b/nptl/sysdeps/unix/sysv/linux/sparc/lowlevellock.h @@ -87,17 +87,17 @@ __lll_mutex_trylock (int *futex) #define lll_mutex_trylock(futex) __lll_mutex_trylock (&(futex)) -extern void __lll_lock_wait (int *futex, int val) attribute_hidden; +extern void __lll_lock_wait (int *futex) attribute_hidden; static inline void __attribute__ ((always_inline)) __lll_mutex_lock (int *futex) { - int val = atomic_exchange_and_add (futex, 1); + int val = atomic_compare_and_exchange_val_acq (futex, 1, 0); if (__builtin_expect (val != 0, 0)) - __lll_lock_wait (futex, val); + __lll_lock_wait (futex); } #define lll_mutex_lock(futex) __lll_mutex_lock (&(futex)) @@ -106,18 +106,15 @@ static inline void __attribute__ ((always_inline)) __lll_mutex_cond_lock (int *futex) { - int val = atomic_exchange_and_add (futex, 2); + int val = atomic_compare_and_exchange_val_acq (futex, 2, 0); if (__builtin_expect (val != 0, 0)) - /* Note, the val + 1 is kind of ugly here. __lll_lock_wait will add - 1 again. But we added 2 to the futex value so this is the right - value which will be passed to the kernel. */ - __lll_lock_wait (futex, val + 1); + __lll_lock_wait (futex); } #define lll_mutex_cond_lock(futex) __lll_mutex_cond_lock (&(futex)) -extern int __lll_timedlock_wait (int *futex, int val, const struct timespec *) +extern int __lll_timedlock_wait (int *futex, const struct timespec *) attribute_hidden; @@ -125,12 +122,11 @@ static inline int __attribute__ ((always_inline)) __lll_mutex_timedlock (int *futex, const struct timespec *abstime) { - int val = atomic_exchange_and_add (futex, 1); + int val = atomic_compare_and_exchange_val_acq (futex, 1, 0); int result = 0; - + if (__builtin_expect (val != 0, 0)) - result = __lll_timedlock_wait (futex, val, abstime); - + result = __lll_timedlock_wait (futex, abstime); return result; } #define lll_mutex_timedlock(futex, abstime) \ diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/libc-lowlevelmutex.S b/nptl/sysdeps/unix/sysv/linux/x86_64/libc-lowlevelmutex.S deleted file mode 100644 index e6dc8677a4..0000000000 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/libc-lowlevelmutex.S +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 2002, 2003 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. - - 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. */ - -/* In libc.so we do not unconditionally use the lock prefix. Only if - the application is using threads. */ -#ifndef UP -# define LOCK \ - cmpl $0, __libc_multiple_threads(%rip); \ - je 0f; \ - lock; \ -0: -#endif - -#include "lowlevelmutex.S" diff --git a/sysdeps/unix/opendir.c b/sysdeps/unix/opendir.c index 2938c67e4a..5e03ed9b20 100644 --- a/sysdeps/unix/opendir.c +++ b/sysdeps/unix/opendir.c @@ -26,6 +26,7 @@ #include <sys/stat.h> #include <unistd.h> #include <stdio.h> +#include <string.h> #include <dirstream.h> #include <not-cancel.h> |