2012-12-22 09:03:04 +00:00
|
|
|
/* force-elision.h: Automatic enabling of elision for mutexes
|
2020-01-01 00:14:33 +00:00
|
|
|
Copyright (C) 2013-2020 Free Software Foundation, Inc.
|
2012-12-22 09:03:04 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
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
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2012-12-22 09:03:04 +00:00
|
|
|
|
|
|
|
/* Automatically enable elision for existing user lock kinds. */
|
|
|
|
#define FORCE_ELISION(m, s) \
|
2018-10-17 10:23:04 +00:00
|
|
|
if (__pthread_force_elision) \
|
2012-12-22 09:03:04 +00:00
|
|
|
{ \
|
2018-10-17 10:23:04 +00:00
|
|
|
/* See concurrency notes regarding __kind in \
|
|
|
|
struct __pthread_mutex_s in \
|
|
|
|
sysdeps/nptl/bits/thread-shared-types.h. \
|
|
|
|
\
|
|
|
|
There are the following cases for the kind of a mutex \
|
|
|
|
(The mask PTHREAD_MUTEX_ELISION_FLAGS_NP covers the flags \
|
|
|
|
PTHREAD_MUTEX_ELISION_NP and PTHREAD_MUTEX_NO_ELISION_NP where \
|
|
|
|
only one of both flags can be set): \
|
|
|
|
- both flags are not set: \
|
|
|
|
This is the first lock operation for this mutex. Enable \
|
|
|
|
elision as it is not enabled so far. \
|
|
|
|
Note: It can happen that multiple threads are calling e.g. \
|
|
|
|
pthread_mutex_lock at the same time as the first lock \
|
|
|
|
operation for this mutex. Then elision is enabled for this \
|
|
|
|
mutex by multiple threads. Storing with relaxed MO is enough \
|
|
|
|
as all threads will store the same new value for the kind of \
|
|
|
|
the mutex. But we have to ensure that we always use the \
|
|
|
|
elision path regardless if this thread has enabled elision or \
|
|
|
|
another one. \
|
|
|
|
\
|
|
|
|
- PTHREAD_MUTEX_ELISION_NP flag is set: \
|
|
|
|
Elision was already enabled for this mutex by a previous lock \
|
|
|
|
operation. See case above. Just use the elision path. \
|
|
|
|
\
|
|
|
|
- PTHREAD_MUTEX_NO_ELISION_NP flag is set: \
|
|
|
|
Elision was explicitly disabled by pthread_mutexattr_settype. \
|
|
|
|
Do not use the elision path. \
|
|
|
|
Note: The flag PTHREAD_MUTEX_NO_ELISION_NP will never be \
|
|
|
|
changed after mutex initialization. */ \
|
|
|
|
int mutex_kind = atomic_load_relaxed (&((m)->__data.__kind)); \
|
|
|
|
if ((mutex_kind & PTHREAD_MUTEX_ELISION_FLAGS_NP) == 0) \
|
|
|
|
{ \
|
|
|
|
mutex_kind |= PTHREAD_MUTEX_ELISION_NP; \
|
|
|
|
atomic_store_relaxed (&((m)->__data.__kind), mutex_kind); \
|
|
|
|
} \
|
|
|
|
if ((mutex_kind & PTHREAD_MUTEX_ELISION_NP) != 0) \
|
|
|
|
{ \
|
|
|
|
s; \
|
|
|
|
} \
|
2012-12-22 09:03:04 +00:00
|
|
|
}
|