diff options
author | Florian Weimer <fweimer@redhat.com> | 2020-05-20 15:40:35 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2020-07-06 11:15:58 +0200 |
commit | 706ad1e7af37be1d25fc2359bda006d31fe0d11b (patch) | |
tree | d06e6a96c1d319a1d27fa6b6e87cfadf8bd6ef08 /misc | |
parent | 8f4632deb3545b2949cec5454afc3cb21a0024ea (diff) | |
download | glibc-706ad1e7af37be1d25fc2359bda006d31fe0d11b.tar.gz glibc-706ad1e7af37be1d25fc2359bda006d31fe0d11b.tar.xz glibc-706ad1e7af37be1d25fc2359bda006d31fe0d11b.zip |
Add the __libc_single_threaded variable
The variable is placed in libc.so, and it can be true only in an outer libc, not libcs loaded via dlmopen or static dlopen. Since thread creation from inner namespaces does not work, pthread_create can update __libc_single_threaded directly. Using __libc_early_init and its initial flag, implementation of this variable is very straightforward. A future version may reset the flag during fork (but not in an inner namespace), or after joining all threads except one. Reviewed-by: DJ Delorie <dj@redhat.com>
Diffstat (limited to 'misc')
-rw-r--r-- | misc/Makefile | 5 | ||||
-rw-r--r-- | misc/Versions | 3 | ||||
-rw-r--r-- | misc/single_threaded.c | 27 | ||||
-rw-r--r-- | misc/sys/single_threaded.h | 33 |
4 files changed, 66 insertions, 2 deletions
diff --git a/misc/Makefile b/misc/Makefile index 67c5237f97..58959f6913 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -37,7 +37,8 @@ headers := sys/uio.h bits/uio-ext.h bits/uio_lim.h \ bits/syslog.h bits/syslog-ldbl.h bits/syslog-path.h bits/error.h \ bits/select2.h bits/hwcap.h sys/auxv.h \ sys/sysmacros.h bits/sysmacros.h bits/types/struct_iovec.h \ - bits/err-ldbl.h bits/error-ldbl.h + bits/err-ldbl.h bits/error-ldbl.h \ + sys/single_threaded.h routines := brk sbrk sstk ioctl \ readv writev preadv preadv64 pwritev pwritev64 \ @@ -72,7 +73,7 @@ routines := brk sbrk sstk ioctl \ fgetxattr flistxattr fremovexattr fsetxattr getxattr \ listxattr lgetxattr llistxattr lremovexattr lsetxattr \ removexattr setxattr getauxval ifunc-impl-list makedev \ - allocate_once fd_to_filename + allocate_once fd_to_filename single_threaded generated += tst-error1.mtrace tst-error1-mem.out \ tst-allocate_once.mtrace tst-allocate_once-mem.out diff --git a/misc/Versions b/misc/Versions index e749582369..95666f6548 100644 --- a/misc/Versions +++ b/misc/Versions @@ -161,6 +161,9 @@ libc { GLIBC_2.30 { twalk_r; } + GLIBC_2.32 { + __libc_single_threaded; + } GLIBC_PRIVATE { __madvise; __mktemp; diff --git a/misc/single_threaded.c b/misc/single_threaded.c new file mode 100644 index 0000000000..6d975c0eaa --- /dev/null +++ b/misc/single_threaded.c @@ -0,0 +1,27 @@ +/* Support for single-thread optimizations. Statically linked version. + Copyright (C) 2020 Free Software Foundation, Inc. + 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 + <https://www.gnu.org/licenses/>. */ + +#include <sys/single_threaded.h> + +/* In dynamically linked programs, this variable is initialized in + __libc_early_init (as false for inner libcs). */ +#ifdef SHARED +char __libc_single_threaded; +#else +char __libc_single_threaded = 1; +#endif diff --git a/misc/sys/single_threaded.h b/misc/sys/single_threaded.h new file mode 100644 index 0000000000..648fc2e00a --- /dev/null +++ b/misc/sys/single_threaded.h @@ -0,0 +1,33 @@ +/* Support for single-thread optimizations. + Copyright (C) 2020 Free Software Foundation, Inc. + 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 + <https://www.gnu.org/licenses/>. */ + +#ifndef _SYS_SINGLE_THREADED_H +#define _SYS_SINGLE_THREADED_H + +#include <features.h> + +__BEGIN_DECLS + +/* If this variable is non-zero, then the current thread is the only + thread in the process image. If it is zero, the process might be + multi-threaded. */ +extern char __libc_single_threaded; + +__END_DECLS + +#endif /* _SYS_SINGLE_THREADED_H */ |