2007-07-10 Steven Munroe * pthread_rwlock_rdlock.c (__pthread_rwlock_rdlock): Add LLL_SHARED parameter to lll_futex_wait call. * pthread_rwlock_wrlock.c (__pthread_rwlock_wrlock): Likewise. * sysdeps/unix/sysv/linux/powerpc/pthread_once.c (__pthread_once): Replace lll_futex_wait with lll_private_futex_wait. * sysdeps/unix/sysv/linux/powerpc/sem_post.c (__new_sem_post): Add LLL_SHARED parameter to lll_futex_wake(). * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h: Define LLL_PRIVATE LLL_SHARED, lll_private_futex_wait, lll_private_futex_timed_wait and lll_private_futex_wake. (lll_futex_wait): Add private parameter. Adjust FUTEX_PRIVATE_FLAG bit from private parm before syscall. (lll_futex_timed_wait): Likewise. (lll_futex_wake): Likewise. (lll_futex_wake_unlock): Likewise. (lll_mutex_unlock): Add LLL_SHARED parm to lll_futex_wake call. (lll_robust_mutex_unlock): Likewise. (lll_mutex_unlock_force): Likewise. (lll_wait_tid): Add LLL_SHARED parm to lll_futex_wait call. diff -urN libc25-cvstip-20070710/nptl/pthread_rwlock_rdlock.c libc25/nptl/pthread_rwlock_rdlock.c --- libc25-cvstip-20070710/nptl/pthread_rwlock_rdlock.c 2007-05-26 17:11:31.000000000 -0500 +++ libc25/nptl/pthread_rwlock_rdlock.c 2007-07-11 15:46:33.775044328 -0500 @@ -77,7 +77,9 @@ lll_mutex_unlock (rwlock->__data.__lock); /* Wait for the writer to finish. */ - lll_futex_wait (&rwlock->__data.__readers_wakeup, waitval); + lll_futex_wait (&rwlock->__data.__readers_wakeup, waitval, + // XYZ check mutex flag + LLL_SHARED); /* Get the lock. */ lll_mutex_lock (rwlock->__data.__lock); diff -urN libc25-cvstip-20070710/nptl/pthread_rwlock_wrlock.c libc25/nptl/pthread_rwlock_wrlock.c --- libc25-cvstip-20070710/nptl/pthread_rwlock_wrlock.c 2006-10-28 00:11:15.000000000 -0500 +++ libc25/nptl/pthread_rwlock_wrlock.c 2007-07-13 15:45:04.763093928 -0500 @@ -1,4 +1,4 @@ -/* Copyright (C) 2003 Free Software Foundation, Inc. +/* Copyright (C) 2003, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Martin Schwidefsky , 2003. @@ -68,7 +68,9 @@ lll_mutex_unlock (rwlock->__data.__lock); /* Wait for the writer or reader(s) to finish. */ - lll_futex_wait (&rwlock->__data.__writer_wakeup, waitval); + lll_futex_wait (&rwlock->__data.__writer_wakeup, waitval, + // XYZ check mutex flag + LLL_SHARED); /* Get the lock. */ lll_mutex_lock (rwlock->__data.__lock); diff -urN libc25-cvstip-20070710/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h libc25/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h --- libc25-cvstip-20070710/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h 2007-05-29 23:44:54.000000000 -0500 +++ libc25/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h 2007-07-13 14:41:43.810089800 -0500 @@ -39,37 +39,46 @@ #define FUTEX_TRYLOCK_PI 8 #define FUTEX_PRIVATE_FLAG 128 +/* Values for 'private' parameter of locking macros. Yes, the + definition seems to be backwards. But it is not. The bit will be + reversed before passing to the system call. */ +#define LLL_PRIVATE 0 +#define LLL_SHARED FUTEX_PRIVATE_FLAG + /* Initializer for compatibility lock. */ #define LLL_MUTEX_LOCK_INITIALIZER (0) -#define lll_futex_wait(futexp, val) \ +#define lll_futex_wait(futexp, val, private) \ ({ \ INTERNAL_SYSCALL_DECL (__err); \ + long int opt_flags = (FUTEX_WAIT | LLL_SHARED) ^ private; \ long int __ret; \ \ __ret = INTERNAL_SYSCALL (futex, __err, 4, \ - (futexp), FUTEX_WAIT, (val), 0); \ + (futexp), opt_flags, (val), 0); \ INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \ }) -#define lll_futex_timed_wait(futexp, val, timespec) \ +#define lll_futex_timed_wait(futexp, val, timespec, private) \ ({ \ INTERNAL_SYSCALL_DECL (__err); \ + long int opt_flags = (FUTEX_WAIT | LLL_SHARED) ^ private; \ long int __ret; \ \ __ret = INTERNAL_SYSCALL (futex, __err, 4, \ - (futexp), FUTEX_WAIT, (val), (timespec)); \ + (futexp), opt_flags, (val), (timespec)); \ INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \ }) -#define lll_futex_wake(futexp, nr) \ +#define lll_futex_wake(futexp, nr, private) \ ({ \ INTERNAL_SYSCALL_DECL (__err); \ + long int opt_flags = (FUTEX_WAKE | LLL_SHARED) ^ private; \ long int __ret; \ \ __ret = INTERNAL_SYSCALL (futex, __err, 4, \ - (futexp), FUTEX_WAKE, (nr), 0); \ + (futexp), opt_flags, (nr), 0); \ INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \ }) @@ -97,17 +106,69 @@ }) /* Returns non-zero if error happened, zero if success. */ -#define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2) \ +#define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2, private) \ ({ \ INTERNAL_SYSCALL_DECL (__err); \ + long int opt_flags = (FUTEX_WAKE_OP | LLL_SHARED) ^ private; \ + long int opt_flag2 = (FUTEX_OP_CLEAR_WAKE_IF_GT_ONE | LLL_SHARED) \ + ^ private; \ long int __ret; \ \ __ret = INTERNAL_SYSCALL (futex, __err, 6, \ - (futexp), FUTEX_WAKE_OP, (nr_wake), \ + (futexp), opt_flags, (nr_wake), \ (nr_wake2), (futexp2), \ - FUTEX_OP_CLEAR_WAKE_IF_GT_ONE); \ + opt_flag2); \ INTERNAL_SYSCALL_ERROR_P (__ret, __err); \ }) + + +#define lll_private_futex_wait(futexp, val) \ + lll_private_futex_timed_wait (futexp, val, NULL) + + +#ifdef __ASSUME_PRIVATE_FUTEX +# define lll_private_futex_timed_wait(futexp, val, timeout) \ + ({ \ + INTERNAL_SYSCALL_DECL (__err); \ + long int __ret; \ + \ + __ret = INTERNAL_SYSCALL (futex, __err, 4, \ + (futexp), (FUTEX_WAIT | FUTEX_PRIVATE_FLAG), \ + (val), (timeout)); \ + INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \ + }) + +# define lll_private_futex_wake(futexp, val) \ + ({ \ + INTERNAL_SYSCALL_DECL (__err); \ + long int __ret; \ + \ + __ret = INTERNAL_SYSCALL (futex, __err, 4, \ + (futexp), (FUTEX_WAKE | FUTEX_PRIVATE_FLAG), \ + (val), 0); \ + INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \ + }) +#else +# define lll_private_futex_timed_wait(futexp, val, timeout) \ + ({ \ + INTERNAL_SYSCALL_DECL (__err); \ + long int __ret; \ + \ + __ret = INTERNAL_SYSCALL (futex, __err, 4, \ + (futexp), FUTEX_WAIT, (val), (timeout)); \ + INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \ + }) + +# define lll_private_futex_wake(futexp, val) \ + ({ \ + INTERNAL_SYSCALL_DECL (__err); \ + long int __ret; \ + \ + __ret = INTERNAL_SYSCALL (futex, __err, 4, \ + (futexp), FUTEX_WAKE, (val), 0); \ + INTERNAL_SYSCALL_ERROR_P (__ret, __err) ? -__ret : __ret; \ + }) +#endif #ifdef UP # define __lll_acq_instr "" @@ -230,7 +291,7 @@ int *__futex = &(lock); \ int __val = atomic_exchange_rel (__futex, 0); \ if (__builtin_expect (__val > 1, 0)) \ - lll_futex_wake (__futex, 1); \ + lll_futex_wake (__futex, 1, LLL_SHARED); \ })) #define lll_robust_mutex_unlock(lock) \ @@ -238,7 +299,7 @@ int *__futex = &(lock); \ int __val = atomic_exchange_rel (__futex, 0); \ if (__builtin_expect (__val & FUTEX_WAITERS, 0)) \ - lll_futex_wake (__futex, 1); \ + lll_futex_wake (__futex, 1, LLL_SHARED); \ })) #define lll_mutex_unlock_force(lock) \ @@ -246,7 +307,7 @@ int *__futex = &(lock); \ *__futex = 0; \ __asm __volatile (__lll_rel_instr ::: "memory"); \ - lll_futex_wake (__futex, 1); \ + lll_futex_wake (__futex, 1, LLL_SHARED); \ })) #define lll_mutex_islocked(futex) \ @@ -281,7 +342,7 @@ do { \ __typeof (tid) __tid; \ while ((__tid = (tid)) != 0) \ - lll_futex_wait (&(tid), __tid); \ + lll_futex_wait (&(tid), __tid, LLL_SHARED); \ } while (0) extern int __lll_timedwait_tid (int *, const struct timespec *) diff -urN libc25-cvstip-20070710/nptl/sysdeps/unix/sysv/linux/powerpc/pthread_once.c libc25/nptl/sysdeps/unix/sysv/linux/powerpc/pthread_once.c --- libc25-cvstip-20070710/nptl/sysdeps/unix/sysv/linux/powerpc/pthread_once.c 2004-09-08 01:07:35.000000000 -0500 +++ libc25/nptl/sysdeps/unix/sysv/linux/powerpc/pthread_once.c 2007-07-13 15:44:06.908102352 -0500 @@ -1,4 +1,4 @@ -/* Copyright (C) 2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Paul Mackerras , 2003. @@ -30,7 +30,7 @@ pthread_once_t *once_control = (pthread_once_t *) arg; *once_control = 0; - lll_futex_wake (once_control, INT_MAX); + lll_private_futex_wake (once_control, INT_MAX); } @@ -74,7 +74,7 @@ break; /* Same generation, some other thread was faster. Wait. */ - lll_futex_wait (once_control, oldval); + lll_private_futex_wait (once_control, oldval); } @@ -92,7 +92,7 @@ atomic_increment (once_control); /* Wake up all other threads. */ - lll_futex_wake (once_control, INT_MAX); + lll_private_futex_wake (once_control, INT_MAX); return 0; } diff -urN libc25-cvstip-20070710/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c libc25/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c --- libc25-cvstip-20070710/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c 2007-05-15 01:31:57.000000000 -0500 +++ libc25/nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c 2007-07-13 15:43:52.523158896 -0500 @@ -1,5 +1,5 @@ /* sem_post -- post to a POSIX semaphore. Powerpc version. - Copyright (C) 2003, 2004 Free Software Foundation, Inc. + Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Paul Mackerras , 2003. @@ -33,7 +33,7 @@ __asm __volatile (__lll_rel_instr ::: "memory"); int nr = atomic_increment_val (futex); - int err = lll_futex_wake (futex, nr); + int err = lll_futex_wake (futex, nr, LLL_SHARED); if (__builtin_expect (err, 0) < 0) { __set_errno (-err);