2005-03-24 Jakub Jelinek * sysdeps/unix/sysv/linux/powerpc/lowlevellock.h (FUTEX_WAKE_OP, FUTEX_OP_CLEAR_WAKE_IF_GT_ONE): Define. (lll_futex_wake_unlock): Define. * sysdeps/pthread/pthread_cond_signal.c (__pthread_cond_signal): Use lll_futex_wake_unlock. * sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S (FUTEX_WAKE_OP, FUTEX_OP_CLEAR_WAKE_IF_GT_ONE): Define. (__pthread_cond_signal): Use FUTEX_WAKE_OP. * sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S (FUTEX_WAKE_OP, FUTEX_OP_CLEAR_WAKE_IF_GT_ONE): Define. (__pthread_cond_signal): Use FUTEX_WAKE_OP. --- libc/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h.jj 2004-07-12 17:50:23.000000000 +0200 +++ libc/nptl/sysdeps/unix/sysv/linux/powerpc/lowlevellock.h 2005-03-21 18:59:47.000000000 +0100 @@ -33,6 +33,8 @@ #define FUTEX_WAKE 1 #define FUTEX_REQUEUE 3 #define FUTEX_CMP_REQUEUE 4 +#define FUTEX_WAKE_OP 5 +#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1) /* Initializer for compatibility lock. */ #define LLL_MUTEX_LOCK_INITIALIZER (0) @@ -79,6 +81,19 @@ INTERNAL_SYSCALL_ERROR_P (__ret, __err); \ }) +/* Returns non-zero if error happened, zero if success. */ +#define lll_futex_wake_unlock(futexp, nr_wake, nr_wake2, futexp2) \ + ({ \ + INTERNAL_SYSCALL_DECL (__err); \ + long int __ret; \ + \ + __ret = INTERNAL_SYSCALL (futex, __err, 6, \ + (futexp), FUTEX_WAKE_OP, (nr_wake), \ + (nr_wake2), (futexp2), \ + (FUTEX_OP_CLEAR_WAKE_IF_GT_ONE)); \ + INTERNAL_SYSCALL_ERROR_P (__ret, __err); \ + }) + #ifdef UP # define __lll_acq_instr "" # define __lll_rel_instr "" --- libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S.jj 2004-06-11 14:45:54.000000000 +0200 +++ libc/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S 2005-03-23 23:30:43.000000000 +0100 @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2002. @@ -31,7 +31,9 @@ #define SYS_futex 202 #define FUTEX_WAIT 0 #define FUTEX_WAKE 1 -#define FUTEX_REQUEUE 3 +#define FUTEX_WAKE_OP 5 + +#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1) #define EINVAL 22 @@ -66,9 +68,30 @@ __pthread_cond_signal: addl $1, (%rdi) /* Wake up one thread. */ - movq $FUTEX_WAKE, %rsi + movq $FUTEX_WAKE_OP, %rsi movq $SYS_futex, %rax movq $1, %rdx + movq $1, %r10 +#if cond_lock != 0 + addq $cond_lock, %r8 +#endif + movq $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %r9 + syscall +#if cond_lock != 0 + subq $cond_lock, %r8 +#endif + /* For any kind of error, we try again with WAKE. + The general test also covers running on old kernels. */ + cmpq $-4095, %rax + jae 7f + + xorl %eax, %eax + retq + +7: movq $FUTEX_WAKE, %rsi + movq $SYS_futex, %rax + /* %rdx should be 1 already from $FUTEX_WAKE_OP syscall. + movq $1, %rdx */ syscall /* Unlock. */ --- libc/nptl/sysdeps/pthread/pthread_cond_signal.c.jj 2004-06-11 14:45:52.000000000 +0200 +++ libc/nptl/sysdeps/pthread/pthread_cond_signal.c 2005-03-23 19:34:23.000000000 +0100 @@ -43,6 +43,11 @@ __pthread_cond_signal (cond) ++cond->__data.__futex; /* Wake one. */ + if (! __builtin_expect (lll_futex_wake_unlock (&cond->__data.__futex, 1, + 1, &cond->__data.__lock), + 0)) + return 0; + lll_futex_wake (&cond->__data.__futex, 1); } --- libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S.jj 2004-06-11 14:45:52.000000000 +0200 +++ libc/nptl/sysdeps/unix/sysv/linux/i386/i486/pthread_cond_signal.S 2005-03-24 13:22:48.000000000 +0100 @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2002. @@ -31,7 +31,9 @@ #define SYS_futex 240 #define FUTEX_WAIT 0 #define FUTEX_WAKE 1 -#define FUTEX_REQUEUE 3 +#define FUTEX_WAKE_OP 5 + +#define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1) #define EINVAL 22 @@ -79,21 +81,46 @@ __pthread_cond_signal: addl $1, (%ebx) /* Wake up one thread. */ - movl $FUTEX_WAKE, %ecx + pushl %esi + pushl %ebp + movl $FUTEX_WAKE_OP, %ecx movl $SYS_futex, %eax movl $1, %edx + movl $1, %esi + movl $FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %ebp + /* FIXME: Until Ingo fixes 4G/4G vDSO, 6 arg syscalls are broken for + sysenter. + ENTER_KERNEL */ + int $0x80 + popl %ebp + popl %esi + + /* For any kind of error, we try again with WAKE. + The general test also covers running on old kernels. */ + cmpl $-4095, %eax + jae 7f + +6: xorl %eax, %eax + popl %edi + popl %ebx + ret + +7: movl $FUTEX_WAKE, %ecx + movl $SYS_futex, %eax + /* %edx should be 1 already from $FUTEX_WAKE_OP syscall. + movl $1, %edx */ ENTER_KERNEL /* Unlock. Note that at this point %edi always points to cond_lock. */ 4: LOCK subl $1, (%edi) - jne 5f + je 6b -6: xorl %eax, %eax - popl %edi - popl %ebx - ret + /* Unlock in loop requires wakeup. */ +5: movl %edi, %eax + call __lll_mutex_unlock_wake + jmp 6b /* Initial locking failed. */ 1: @@ -105,10 +132,6 @@ __pthread_cond_signal: call __lll_mutex_lock_wait jmp 2b - /* Unlock in loop requires wakeup. */ -5: movl %edi, %eax - call __lll_mutex_unlock_wake - jmp 6b .size __pthread_cond_signal, .-__pthread_cond_signal versioned_symbol (libpthread, __pthread_cond_signal, pthread_cond_signal, GLIBC_2_3_2)