]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Replace __libc_multiple_threads with __libc_single_threaded
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 7 Jun 2022 16:09:40 +0000 (13:09 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 5 Jul 2022 13:14:47 +0000 (10:14 -0300)
And also fixes the SINGLE_THREAD_P macro for SINGLE_THREAD_BY_GLOBAL,
since header inclusion single-thread.h is in the wrong order, the define
needs to come before including sysdeps/unix/sysdep.h.  The macro
is now moved to a per-arch single-threade.h header.

The SINGLE_THREAD_P is used on some more places.

Checked on aarch64-linux-gnu and x86_64-linux-gnu.

22 files changed:
nptl/Makefile
nptl/allocatestack.c
nptl/libc_multiple_threads.c [deleted file]
nptl/pthread_cancel.c
posix/fork.c
sysdeps/nptl/setxid.h
sysdeps/unix/sysv/linux/aarch64/single-thread.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/aarch64/sysdep.h
sysdeps/unix/sysv/linux/alpha/sysdep.h
sysdeps/unix/sysv/linux/arc/single-thread.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/arc/sysdep.h
sysdeps/unix/sysv/linux/arm/single-thread.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/arm/sysdep.h
sysdeps/unix/sysv/linux/hppa/single-thread.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/hppa/sysdep.h
sysdeps/unix/sysv/linux/microblaze/single-thread.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/microblaze/sysdep.h
sysdeps/unix/sysv/linux/s390/single-thread.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/s390/sysdep.h
sysdeps/unix/sysv/linux/single-thread.h
sysdeps/unix/sysv/linux/x86_64/single-thread.h [new file with mode: 0644]
sysdeps/unix/sysv/linux/x86_64/sysdep.h

index b585663974df724ad3d8dc48c2c0f431122b3b37..3d2ce8af8a428cf0a7dc41ee9416aaa4e472e467 100644 (file)
@@ -50,7 +50,6 @@ routines = \
   events \
   futex-internal \
   libc-cleanup \
-  libc_multiple_threads \
   lowlevellock \
   nptl-stack \
   nptl_deallocate_tsd \
index 01a282f3f652662f82e63c54954d13cf92eafcda..98f5f6dd85afe2e14b29600b4fdc565364b79671 100644 (file)
@@ -292,9 +292,6 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
 
       /* This is at least the second thread.  */
       pd->header.multiple_threads = 1;
-#ifndef TLS_MULTIPLE_THREADS_IN_TCB
-      __libc_multiple_threads = 1;
-#endif
 
 #ifdef NEED_DL_SYSINFO
       SETUP_THREAD_SYSINFO (pd);
@@ -413,9 +410,6 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
 
          /* This is at least the second thread.  */
          pd->header.multiple_threads = 1;
-#ifndef TLS_MULTIPLE_THREADS_IN_TCB
-         __libc_multiple_threads = 1;
-#endif
 
 #ifdef NEED_DL_SYSINFO
          SETUP_THREAD_SYSINFO (pd);
diff --git a/nptl/libc_multiple_threads.c b/nptl/libc_multiple_threads.c
deleted file mode 100644 (file)
index 0c2dc33..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Copyright (C) 2002-2022 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 <pthreadP.h>
-
-#if IS_IN (libc)
-# ifndef TLS_MULTIPLE_THREADS_IN_TCB
-/* Variable set to a nonzero value either if more than one thread runs or ran,
-   or if a single-threaded process is trying to cancel itself.  See
-   nptl/descr.h for more context on the single-threaded process case.  */
-int __libc_multiple_threads;
-libc_hidden_data_def (__libc_multiple_threads)
-# endif
-#endif
index e67b2df5cc56240e186cb360bf78fa36ff085760..459317df4940266f7daf548250b95c8700c22dbe 100644 (file)
@@ -161,7 +161,7 @@ __pthread_cancel (pthread_t th)
           points get executed.  */
        THREAD_SETMEM (THREAD_SELF, header.multiple_threads, 1);
 #ifndef TLS_MULTIPLE_THREADS_IN_TCB
-      __libc_multiple_threads = 1;
+       __libc_single_threaded_internal = 0;
 #endif
     }
   while (!atomic_compare_exchange_weak_acquire (&pd->cancelhandling, &oldval,
index 987916a175accdbb487416de041699a096bf17c5..cee5ae83c8f97cf998317ec8b480de651f0907c5 100644 (file)
@@ -45,7 +45,7 @@ __libc_fork (void)
      requirement for fork (Austin Group tracker issue #62) this is
      best effort to make is async-signal-safe at least for single-thread
      case.  */
-  bool multiple_threads = __libc_single_threaded_internal == 0;
+  bool multiple_threads = !SINGLE_THREAD_P;
   uint64_t lastrun;
 
   lastrun = __run_prefork_handlers (multiple_threads);
index b87cad7b18529857618015793492a8c8fc4d9c0f..3a412179ac1dda5809b75b2c7461c14d750cf320 100644 (file)
@@ -29,7 +29,7 @@
 #define INLINE_SETXID_SYSCALL(name, nr, args...) \
   ({                                                                   \
     int __result;                                                      \
-    if (!__libc_single_threaded_internal)                              \
+    if (!SINGLE_THREAD_P)                                              \
       {                                                                        \
        struct xid_command __cmd;                                       \
        __cmd.syscall_no = __NR_##name;                                 \
diff --git a/sysdeps/unix/sysv/linux/aarch64/single-thread.h b/sysdeps/unix/sysv/linux/aarch64/single-thread.h
new file mode 100644 (file)
index 0000000..a5d3a2a
--- /dev/null
@@ -0,0 +1,2 @@
+#define SINGLE_THREAD_BY_GLOBAL
+#include_next <single-thread.h>
index 3b230dccf1d1af207e806f8935fc35995a622ecc..f1853e012ffd2b6d023851a91e2960226ffaccfb 100644 (file)
 # define HAVE_CLOCK_GETTIME64_VSYSCALL "__kernel_clock_gettime"
 # define HAVE_GETTIMEOFDAY_VSYSCALL    "__kernel_gettimeofday"
 
-# define SINGLE_THREAD_BY_GLOBAL               1
-
 # undef INTERNAL_SYSCALL_RAW
 # define INTERNAL_SYSCALL_RAW(name, nr, args...)               \
   ({ long _sys_result;                                         \
index 3051a744b464bc6162d72879c7d10f20294fbe9c..77ec2b540021ca175fffb8350e2a02067e1b80e0 100644 (file)
@@ -32,8 +32,6 @@
 #undef SYS_ify
 #define SYS_ify(syscall_name)  __NR_##syscall_name
 
-#define SINGLE_THREAD_BY_GLOBAL 1
-
 #ifdef __ASSEMBLER__
 #include <asm/pal.h>
 #include <alpha/regdef.h>
diff --git a/sysdeps/unix/sysv/linux/arc/single-thread.h b/sysdeps/unix/sysv/linux/arc/single-thread.h
new file mode 100644 (file)
index 0000000..a5d3a2a
--- /dev/null
@@ -0,0 +1,2 @@
+#define SINGLE_THREAD_BY_GLOBAL
+#include_next <single-thread.h>
index 29b0e0161cb0b4540129307ed9fa79ef8e1e4a31..d0c1a78381886f92972f5397c1b25b3075d1e565 100644 (file)
@@ -132,8 +132,6 @@ L (call_syscall_err):                       ASM_LINE_SEP    \
 
 #else  /* !__ASSEMBLER__ */
 
-# define SINGLE_THREAD_BY_GLOBAL               1
-
 # if IS_IN (libc)
 extern long int __syscall_error (long int);
 hidden_proto (__syscall_error)
diff --git a/sysdeps/unix/sysv/linux/arm/single-thread.h b/sysdeps/unix/sysv/linux/arm/single-thread.h
new file mode 100644 (file)
index 0000000..a5d3a2a
--- /dev/null
@@ -0,0 +1,2 @@
+#define SINGLE_THREAD_BY_GLOBAL
+#include_next <single-thread.h>
index 7bdd218063e083abbc7f5f3b7bea079dd79f72c0..1f270b961ebfad0813e2f7625e7aedda66790de9 100644 (file)
@@ -408,8 +408,6 @@ __local_syscall_error:                                              \
 #define INTERNAL_SYSCALL_NCS(number, nr, args...)              \
   INTERNAL_SYSCALL_RAW (number, nr, args)
 
-#define SINGLE_THREAD_BY_GLOBAL        1
-
 #endif /* __ASSEMBLER__ */
 
 #endif /* linux/arm/sysdep.h */
diff --git a/sysdeps/unix/sysv/linux/hppa/single-thread.h b/sysdeps/unix/sysv/linux/hppa/single-thread.h
new file mode 100644 (file)
index 0000000..a5d3a2a
--- /dev/null
@@ -0,0 +1,2 @@
+#define SINGLE_THREAD_BY_GLOBAL
+#include_next <single-thread.h>
index 42f7705852ab659061d6ef67005cf593189b96b8..2f339a4bd6e54430824108bd7080dce2f6b512d5 100644 (file)
@@ -474,6 +474,4 @@ L(pre_end):                                 ASM_LINE_SEP    \
 #define PTR_MANGLE(var) (void) (var)
 #define PTR_DEMANGLE(var) (void) (var)
 
-#define SINGLE_THREAD_BY_GLOBAL        1
-
 #endif /* _LINUX_HPPA_SYSDEP_H */
diff --git a/sysdeps/unix/sysv/linux/microblaze/single-thread.h b/sysdeps/unix/sysv/linux/microblaze/single-thread.h
new file mode 100644 (file)
index 0000000..a5d3a2a
--- /dev/null
@@ -0,0 +1,2 @@
+#define SINGLE_THREAD_BY_GLOBAL
+#include_next <single-thread.h>
index dfd631250690d85787786414c0e1957829e77ff3..fda78f6467eab69895915aeaef723741026b5a4a 100644 (file)
@@ -308,8 +308,6 @@ SYSCALL_ERROR_LABEL_DCL:                            \
 # define PTR_MANGLE(var) (void) (var)
 # define PTR_DEMANGLE(var) (void) (var)
 
-# define SINGLE_THREAD_BY_GLOBAL       1
-
 #undef HAVE_INTERNAL_BRK_ADDR_SYMBOL
 #define HAVE_INTERNAL_BRK_ADDR_SYMBOL 1
 
diff --git a/sysdeps/unix/sysv/linux/s390/single-thread.h b/sysdeps/unix/sysv/linux/s390/single-thread.h
new file mode 100644 (file)
index 0000000..a5d3a2a
--- /dev/null
@@ -0,0 +1,2 @@
+#define SINGLE_THREAD_BY_GLOBAL
+#include_next <single-thread.h>
index 78c7e8c7e2d74814ec0072b4b09ebacb72022581..2d0a26779c2c496919faa458d4ac6839039baa7a 100644 (file)
@@ -93,9 +93,6 @@
 #define ASMFMT_5 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6)
 #define ASMFMT_6 , "0" (gpr2), "d" (gpr3), "d" (gpr4), "d" (gpr5), "d" (gpr6), "d" (gpr7)
 
-#define SINGLE_THREAD_BY_GLOBAL                1
-
-
 #define VDSO_NAME  "LINUX_2.6.29"
 #define VDSO_HASH  123718585
 
index 4529a906d2c9b39462986be9709ba61bac1afb66..30dde4e81a2d7e5a9f8cae47f10c17f1f2912b65 100644 (file)
 #ifndef _SINGLE_THREAD_H
 #define _SINGLE_THREAD_H
 
+#ifndef __ASSEMBLER__
+# include <sys/single_threaded.h>
+#endif
+
 /* The default way to check if the process is single thread is by using the
    pthread_t 'multiple_threads' field.  However, for some architectures it is
    faster to either use an extra field on TCB or global variables (the TCB
    The ABI might define SINGLE_THREAD_BY_GLOBAL to enable the single thread
    check to use global variables instead of the pthread_t field.  */
 
-#ifndef __ASSEMBLER__
-extern int __libc_multiple_threads;
-libc_hidden_proto (__libc_multiple_threads)
-#endif
-
 #if !defined SINGLE_THREAD_BY_GLOBAL || IS_IN (rtld)
 # define SINGLE_THREAD_P \
   (THREAD_GETMEM (THREAD_SELF, header.multiple_threads) == 0)
 #else
-# define SINGLE_THREAD_P (__libc_multiple_threads == 0)
+# define SINGLE_THREAD_P (__libc_single_threaded_internal != 0)
 #endif
 
 #define RTLD_SINGLE_THREAD_P SINGLE_THREAD_P
diff --git a/sysdeps/unix/sysv/linux/x86_64/single-thread.h b/sysdeps/unix/sysv/linux/x86_64/single-thread.h
new file mode 100644 (file)
index 0000000..a5d3a2a
--- /dev/null
@@ -0,0 +1,2 @@
+#define SINGLE_THREAD_BY_GLOBAL
+#include_next <single-thread.h>
index e1ce3b62eb21acb9dafdf668fbdbefb1258f4a55..740abefcfd3612928bdd42c605ebdcf341d76667 100644 (file)
 
 # define HAVE_CLONE3_WRAPPER                   1
 
-# define SINGLE_THREAD_BY_GLOBAL               1
-
 #endif /* __ASSEMBLER__ */