Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* sysdeps/unix/sysv/linux/sem_post.c: Only wake threads if old
	value of semaphore was zero.
	* sysdeps/unix/sysv/linux/i386/i486/sem_post.S: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/sem_post.c: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/sem_post.c: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/sem_post.S: Likewise.

	* sysdeps/unix/sysv/linux/x86_64/sem_wait.S: Remove unnecessary
	extra cancellation test.
	* sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S: Likewise.
  • Loading branch information
Ulrich Drepper committed May 15, 2007
1 parent 1d47e92 commit 83d8791
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 54 deletions.
13 changes: 13 additions & 0 deletions nptl/ChangeLog
@@ -1,3 +1,16 @@
2007-05-14 Ulrich Drepper <drepper@redhat.com>

* sysdeps/unix/sysv/linux/sem_post.c: Only wake threads if old
value of semaphore was zero.
* sysdeps/unix/sysv/linux/i386/i486/sem_post.S: Likewise.
* sysdeps/unix/sysv/linux/powerpc/sem_post.c: Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc32/sem_post.c: Likewise.
* sysdeps/unix/sysv/linux/x86_64/sem_post.S: Likewise.

* sysdeps/unix/sysv/linux/x86_64/sem_wait.S: Remove unnecessary
extra cancellation test.
* sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S: Likewise.

2007-05-10 Ulrich Drepper <drepper@redhat.com>

* descr.h (struct pthread): Rearrange members to fill hole in
Expand Down
7 changes: 5 additions & 2 deletions nptl/sysdeps/unix/sysv/linux/i386/i486/sem_post.S
@@ -1,4 +1,4 @@
/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
/* Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
Expand Down Expand Up @@ -44,9 +44,12 @@ __new_sem_post:
LOCK
xaddl %edx, (%ebx)

testl %edx, %edx
jne 2f

movl $SYS_futex, %eax
movl $FUTEX_WAKE, %ecx
addl $1, %edx
movl $1, %edx
ENTER_KERNEL

testl %eax, %eax
Expand Down
14 changes: 8 additions & 6 deletions nptl/sysdeps/unix/sysv/linux/powerpc/sem_post.c
@@ -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 <paulus@au.ibm.com>, 2003.
Expand Down Expand Up @@ -32,12 +32,14 @@ __new_sem_post (sem_t *sem)
int *futex = (int *) sem;

__asm __volatile (__lll_rel_instr ::: "memory");
int nr = atomic_increment_val (futex);
int err = lll_futex_wake (futex, nr);
if (__builtin_expect (err, 0) < 0)
if (atomic_increment_val (futex) == 1)
{
__set_errno (-err);
return -1;
int err = lll_futex_wake (futex, 1);
if (__builtin_expect (err, 0) < 0)
{
__set_errno (-err);
return -1;
}
}
return 0;
}
Expand Down
14 changes: 8 additions & 6 deletions nptl/sysdeps/unix/sysv/linux/sem_post.c
@@ -1,5 +1,5 @@
/* sem_post -- post to a POSIX semaphore. Generic futex-using 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 Jakub Jelinek <jakub@redhat.com>, 2003.
Expand Down Expand Up @@ -31,12 +31,14 @@ __new_sem_post (sem_t *sem)
{
int *futex = (int *) sem;

int nr = atomic_increment_val (futex);
int err = lll_futex_wake (futex, nr);
if (__builtin_expect (err, 0) < 0)
if (atomic_increment_val (futex) == 1)
{
__set_errno (-err);
return -1;
int err = lll_futex_wake (futex, 1);
if (__builtin_expect (err, 0) < 0)
{
__set_errno (-err);
return -1;
}
}
return 0;
}
Expand Down
13 changes: 8 additions & 5 deletions nptl/sysdeps/unix/sysv/linux/sparc/sparc32/sem_post.c
@@ -1,5 +1,5 @@
/* sem_post -- post to a POSIX semaphore. SPARC version.
Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
Copyright (C) 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
Expand Down Expand Up @@ -39,11 +39,14 @@ __new_sem_post (sem_t *sem)
nr = ++*futex;
__sparc32_atomic_do_unlock24 (futex + 1);
}
int err = lll_futex_wake (futex, nr);
if (__builtin_expect (err, 0) < 0)
if (nr == 1)
{
__set_errno (-err);
return -1;
int err = lll_futex_wake (futex, 1);
if (__builtin_expect (err, 0) < 0)
{
__set_errno (-err);
return -1;
}
}
return 0;
}
Expand Down
9 changes: 6 additions & 3 deletions nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
@@ -1,4 +1,4 @@
/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
/* Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
Expand Down Expand Up @@ -41,15 +41,18 @@ sem_post:
LOCK
xaddl %edx, (%rdi)

testl %edx, %edx
jne 2f

movl $SYS_futex, %eax
movl $FUTEX_WAKE, %esi
incl %edx
movl $1, %edx
syscall

testq %rax, %rax
js 1f

xorl %eax, %eax
2: xorl %eax, %eax
retq

1:
Expand Down
19 changes: 1 addition & 18 deletions nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
@@ -1,4 +1,4 @@
/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
/* Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
Expand Down Expand Up @@ -40,12 +40,6 @@
.align 16
cfi_startproc
sem_timedwait:
/* First check for cancellation. */
movl %fs:CANCELHANDLING, %eax
andl $0xfffffff9, %eax
cmpl $8, %eax
je 11f

movl (%rdi), %eax
2: testl %eax, %eax
je 1f
Expand Down Expand Up @@ -160,16 +154,5 @@ sem_timedwait:

orl $-1, %eax
jmp 10b
cfi_adjust_cfa_offset(-48)
cfi_restore(14)
cfi_restore(13)
cfi_restore(12)

11: /* Canceled. */
movq $0xffffffffffffffff, %fs:RESULT
LOCK
orl $0x10, %fs:CANCELHANDLING
movq %fs:CLEANUP_JMP_BUF, %rdi
jmp HIDDEN_JUMPTARGET (__pthread_unwind)
cfi_endproc
.size sem_timedwait,.-sem_timedwait
15 changes: 1 addition & 14 deletions nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
@@ -1,4 +1,4 @@
/* Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
/* Copyright (C) 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
Expand Down Expand Up @@ -37,12 +37,6 @@
.align 16
cfi_startproc
sem_wait:
/* First check for cancellation. */
movl %fs:CANCELHANDLING, %eax
andl $0xfffffff9, %eax
cmpl $8, %eax
je 4f

pushq %r12
cfi_adjust_cfa_offset(8)
cfi_offset(12, -16)
Expand Down Expand Up @@ -109,12 +103,5 @@ sem_wait:
cfi_restore(12)

retq

4: /* Canceled. */
movq $0xffffffffffffffff, %fs:RESULT
LOCK
orl $0x10, %fs:CANCELHANDLING
movq %fs:CLEANUP_JMP_BUF, %rdi
jmp HIDDEN_JUMPTARGET (__pthread_unwind)
cfi_endproc
.size sem_wait,.-sem_wait

0 comments on commit 83d8791

Please sign in to comment.