]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
nptl: Move internal __nptl_nthreads variable into libc
authorFlorian Weimer <fweimer@redhat.com>
Wed, 21 Apr 2021 17:49:50 +0000 (19:49 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 21 Apr 2021 17:49:50 +0000 (19:49 +0200)
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
nptl/Makefile
nptl/Versions
nptl/nptl-init.c
nptl/nptl_nthreads.c [new file with mode: 0644]
nptl/pthreadP.h
nptl/pthread_create.c
nptl_db/structs.def
sysdeps/nptl/libc_start_call_main.h
sysdeps/nptl/pthread-functions.h

index 1d3781062cc07fae246f74e920b2c20db11840be..dce54d02dfb49810e5ca9161f6495e785b982136 100644 (file)
@@ -45,6 +45,7 @@ routines = \
   libc_multiple_threads \
   libc_pthread_init \
   lowlevellock \
+  nptl_nthreads \
   old_pthread_cond_destroy \
   old_pthread_cond_init \
   pthread_atfork \
index 193376c827861be7dc5f9fa410b7b7203d1287b7..b4ee1bf3090282410fa1ba91c82d61484a196b51 100644 (file)
@@ -106,6 +106,7 @@ libc {
     __lll_lock_wait_private;
     __lll_trylock_elision;
     __lll_unlock_elision;
+    __nptl_nthreads;
     __pthread_attr_copy;
     __pthread_attr_destroy;
     __pthread_attr_init;
index 124799679b420553bdbd86370dbc99ef322da2a8..aad4f21f74ada587aac7e005ba83341128c0a7f3 100644 (file)
@@ -93,7 +93,6 @@ static const struct pthread_functions pthread_functions =
     .ptr___pthread_key_create = __pthread_key_create,
     .ptr___pthread_getspecific = __pthread_getspecific,
     .ptr___pthread_setspecific = __pthread_setspecific,
-    .ptr_nthreads = &__nptl_nthreads,
     .ptr__nptl_deallocate_tsd = __nptl_deallocate_tsd,
     .ptr__nptl_setxid = __nptl_setxid,
     .ptr_set_robust = __nptl_set_robust
diff --git a/nptl/nptl_nthreads.c b/nptl/nptl_nthreads.c
new file mode 100644 (file)
index 0000000..2245bb3
--- /dev/null
@@ -0,0 +1,23 @@
+/* Thread counter variable.
+   Copyright (C) 2021 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>
+
+/* Number of threads running.  */
+unsigned int __nptl_nthreads = 1;
+libc_hidden_data_def (__nptl_nthreads)
index 2e66379441514ebf20baa4f980d45aeba600410c..64ec71c23f47a08bad41d14656f091d07e74e0b0 100644 (file)
@@ -220,7 +220,8 @@ extern struct pthread_key_struct __pthread_keys[PTHREAD_KEYS_MAX];
 hidden_proto (__pthread_keys)
 
 /* Number of threads running.  */
-extern unsigned int __nptl_nthreads attribute_hidden;
+extern unsigned int __nptl_nthreads;
+libc_hidden_proto (__nptl_nthreads)
 
 #ifndef __ASSUME_SET_ROBUST_LIST
 /* Negative if we do not have the system call and we can use it.  */
index f13d8e44a4b5b693d22b01afa76df657b2c6e881..c1c5b241c85c2d6aa3d15808d56697ea88515384 100644 (file)
@@ -59,10 +59,6 @@ static struct rtld_global *__nptl_rtld_global __attribute_used__
   = &_rtld_global;
 #endif
 
-/* Number of threads running.  */
-unsigned int __nptl_nthreads = 1;
-
-
 /* Code to allocate and deallocate a stack.  */
 #include "allocatestack.c"
 
index 8a613dd2f5fc016b6ea73f65d23ec8943aea17d9..8aacbe06342f12c170a56b101728297c959aebd6 100644 (file)
@@ -73,7 +73,7 @@ DB_SYMBOL (nptl_version)
 DB_FUNCTION (__nptl_create_event)
 DB_FUNCTION (__nptl_death_event)
 DB_SYMBOL (__nptl_threads_events)
-DB_VARIABLE (__nptl_nthreads)
+DB_MAIN_VARIABLE (__nptl_nthreads)
 DB_VARIABLE (__nptl_last_event)
 DB_VARIABLE (__nptl_initial_report_events)
 
index 5218e7ab1ec2a997295174cd351ffda14736dd4e..112cc20a7a371ee4c2a37f6de499e6dacde5d878 100644 (file)
@@ -17,6 +17,7 @@
    <https://www.gnu.org/licenses/>.  */
 
 #include <atomic.h>
+#include <nptl/pthreadP.h>
 
 _Noreturn static void
 __libc_start_call_main (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
@@ -69,17 +70,7 @@ __libc_start_call_main (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
       /* One less thread.  Decrement the counter.  If it is zero we
          terminate the entire process.  */
       result = 0;
-# ifdef SHARED
-      unsigned int *ptr = __libc_pthread_functions.ptr_nthreads;
-#  ifdef PTR_DEMANGLE
-      PTR_DEMANGLE (ptr);
-#  endif
-# else
-      extern unsigned int __nptl_nthreads __attribute ((weak));
-      unsigned int *const ptr = &__nptl_nthreads;
-# endif
-
-      if (! atomic_decrement_and_test (ptr))
+      if (! atomic_decrement_and_test (&__nptl_nthreads))
         /* Not much left to do but to exit the thread, not the process.  */
         __exit_thread ();
     }
index 280655fe40eb1e817edb0ca7fe5cac4f9647aac4..2fa698b1daac6617f415b17d1439e1ece543842b 100644 (file)
@@ -55,8 +55,6 @@ struct pthread_functions
   int (*ptr___pthread_key_create) (pthread_key_t *, void (*) (void *));
   void *(*ptr___pthread_getspecific) (pthread_key_t);
   int (*ptr___pthread_setspecific) (pthread_key_t, const void *);
-#define HAVE_PTR_NTHREADS
-  unsigned int *ptr_nthreads;
   void (*ptr__nptl_deallocate_tsd) (void);
   int (*ptr__nptl_setxid) (struct xid_command *);
   void (*ptr_set_robust) (struct pthread *);