From 042e1521c794a945edc43b5bfa7e69ad70420524 Mon Sep 17 00:00:00 2001 From: Carlos O'Donell Date: Wed, 21 Jan 2015 00:46:16 -0500 Subject: Fix semaphore destruction (bug 12674). This commit fixes semaphore destruction by either using 64b atomic operations (where available), or by using two separate fields when only 32b atomic operations are available. In the latter case, we keep a conservative estimate of whether there are any waiting threads in one bit of the field that counts the number of available tokens, thus allowing sem_post to atomically both add a token and determine whether it needs to call futex_wake. See: https://sourceware.org/ml/libc-alpha/2014-12/msg00155.html --- sysdeps/unix/sysv/linux/powerpc/sem_post.c | 71 ------------------------------ 1 file changed, 71 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/powerpc/sem_post.c (limited to 'sysdeps/unix/sysv/linux/powerpc') diff --git a/sysdeps/unix/sysv/linux/powerpc/sem_post.c b/sysdeps/unix/sysv/linux/powerpc/sem_post.c deleted file mode 100644 index 6a4e46fb9d..0000000000 --- a/sysdeps/unix/sysv/linux/powerpc/sem_post.c +++ /dev/null @@ -1,71 +0,0 @@ -/* sem_post -- post to a POSIX semaphore. Powerpc version. - Copyright (C) 2003-2015 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Paul Mackerras , 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, see - . */ - -#include -#include -#include -#include -#include - -#include - -int -__new_sem_post (sem_t *sem) -{ - struct new_sem *isem = (struct new_sem *) sem; - - __asm __volatile (__ARCH_REL_INSTR ::: "memory"); - atomic_increment (&isem->value); - __asm __volatile (__ARCH_ACQ_INSTR ::: "memory"); - if (isem->nwaiters > 0) - { - int err = lll_futex_wake (&isem->value, 1, - isem->private ^ FUTEX_PRIVATE_FLAG); - if (__builtin_expect (err, 0) < 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) - -int -attribute_compat_text_section -__old_sem_post (sem_t *sem) -{ - int *futex = (int *) sem; - - __asm __volatile (__ARCH_REL_INSTR ::: "memory"); - (void) atomic_increment_val (futex); - /* We always have to assume it is a shared semaphore. */ - int err = lll_futex_wake (futex, 1, LLL_SHARED); - if (__builtin_expect (err, 0) < 0) - { - __set_errno (-err); - return -1; - } - return 0; -} - -compat_symbol (libpthread, __old_sem_post, sem_post, GLIBC_2_0); -#endif -- cgit 1.4.1