unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer via Libc-alpha <libc-alpha@sourceware.org>
To: libc-alpha@sourceware.org
Subject: [PATCH v4 11/37] nptl: Move internal __nptl_nthreads variable into libc
Date: Fri, 16 Apr 2021 11:21:14 +0200	[thread overview]
Message-ID: <db9c649c44812cebda07c3827b638f841f708bbc.1618564630.git.fweimer@redhat.com> (raw)
In-Reply-To: <cover.1618564630.git.fweimer@redhat.com>

Reviewed-by: Adhemerval Zanella   <adhemerval.zanella@linaro.org>
---
 nptl/Makefile                       |  1 +
 nptl/Versions                       |  1 +
 nptl/nptl-init.c                    |  1 -
 nptl/nptl_nthreads.c                | 23 +++++++++++++++++++++++
 nptl/pthreadP.h                     |  3 ++-
 nptl/pthread_create.c               |  4 ----
 nptl_db/structs.def                 |  2 +-
 sysdeps/nptl/libc_start_call_main.h | 13 ++-----------
 sysdeps/nptl/pthread-functions.h    |  2 --
 9 files changed, 30 insertions(+), 20 deletions(-)
 create mode 100644 nptl/nptl_nthreads.c

diff --git a/nptl/Makefile b/nptl/Makefile
index ea2554a525..5bfa721596 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -45,6 +45,7 @@ routines = \
   libc_multiple_threads \
   libc_pthread_init \
   lowlevellock \
+  nptl_nthreads \
   old_pthread_cond_destroy \
   old_pthread_cond_init \
   pthread_atfork \
diff --git a/nptl/Versions b/nptl/Versions
index 193376c827..b4ee1bf309 100644
--- a/nptl/Versions
+++ b/nptl/Versions
@@ -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;
diff --git a/nptl/nptl-init.c b/nptl/nptl-init.c
index 124799679b..aad4f21f74 100644
--- a/nptl/nptl-init.c
+++ b/nptl/nptl-init.c
@@ -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
index 0000000000..2245bb3c76
--- /dev/null
+++ b/nptl/nptl_nthreads.c
@@ -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)
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index 2e66379441..64ec71c23f 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -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.  */
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 6c645aff48..350bf03f5d 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -51,10 +51,6 @@ static td_thr_events_t __nptl_threads_events __attribute_used__;
 /* Pointer to descriptor with the last event.  */
 static struct pthread *__nptl_last_event __attribute_used__;
 
-/* Number of threads running.  */
-unsigned int __nptl_nthreads = 1;
-
-
 /* Code to allocate and deallocate a stack.  */
 #include "allocatestack.c"
 
diff --git a/nptl_db/structs.def b/nptl_db/structs.def
index 999a9fc35a..d0e1cb659a 100644
--- a/nptl_db/structs.def
+++ b/nptl_db/structs.def
@@ -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)
 
diff --git a/sysdeps/nptl/libc_start_call_main.h b/sysdeps/nptl/libc_start_call_main.h
index 5218e7ab1e..112cc20a7a 100644
--- a/sysdeps/nptl/libc_start_call_main.h
+++ b/sysdeps/nptl/libc_start_call_main.h
@@ -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 ();
     }
diff --git a/sysdeps/nptl/pthread-functions.h b/sysdeps/nptl/pthread-functions.h
index 280655fe40..2fa698b1da 100644
--- a/sysdeps/nptl/pthread-functions.h
+++ b/sysdeps/nptl/pthread-functions.h
@@ -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 *);
-- 
2.30.2



  parent reply	other threads:[~2021-04-16  9:21 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16  9:20 [PATCH v4 00/37] libpthread: Remove NPTL forwarders Florian Weimer via Libc-alpha
2021-04-16  9:20 ` [PATCH v4 01/37] nptl: Move pthread_mutex_consistent into libc Florian Weimer via Libc-alpha
2021-04-16  9:20 ` [PATCH v4 02/37] nptl: Move __pthread_cleanup_routine " Florian Weimer via Libc-alpha
2021-04-16  9:20 ` [PATCH v4 03/37] nptl: Move legacy unwinding implementation " Florian Weimer via Libc-alpha
2021-04-16  9:20 ` [PATCH v4 04/37] nptl: Move legacy cancelation handling into libc as compat symbols Florian Weimer via Libc-alpha
2021-04-16  9:20 ` [PATCH v4 05/37] nptl: Remove longjmp, siglongjmp from libpthread Florian Weimer via Libc-alpha
2021-04-16  9:20 ` [PATCH v4 06/37] x86: Restore compile-time check for shadow stack pointer in longjmp Florian Weimer via Libc-alpha
2021-04-16  9:20 ` [PATCH v4 07/37] nptl: Move __pthread_cleanup_upto into libc Florian Weimer via Libc-alpha
2021-04-16  9:20 ` [PATCH v4 08/37] nptl: Move pthread_once and __pthread_once " Florian Weimer via Libc-alpha
2021-04-16  9:21 ` [PATCH v4 09/37] nptl: Move __pthread_unwind_next " Florian Weimer via Libc-alpha
2021-04-16  9:21 ` [PATCH v4 10/37] csu: Move calling main out of __libc_start_main_impl Florian Weimer via Libc-alpha
2021-04-16  9:21 ` Florian Weimer via Libc-alpha [this message]
2021-04-16  9:21 ` [PATCH v4 12/37] nptl_db: Introduce DB_MAIN_ARRAY_VARIABLE Florian Weimer via Libc-alpha
2021-04-16  9:21 ` [PATCH v4 13/37] nptl: Move __pthread_keys global variable into libc Florian Weimer via Libc-alpha
2021-04-16  9:21 ` [PATCH v4 14/37] nptl: Move __nptl_deallocate_tsd " Florian Weimer via Libc-alpha
2021-04-16  9:21 ` [PATCH v4 15/37] nptl: Move pthread_exit " Florian Weimer via Libc-alpha
2021-04-16  9:22 ` [PATCH v4 16/37] nptl: Move pthread_setcancelstate " Florian Weimer via Libc-alpha
2021-04-16  9:22 ` [PATCH v4 17/37] nptl: Move pthread_setcanceltype " Florian Weimer via Libc-alpha
2021-04-16  9:22 ` [PATCH v4 18/37] nptl: Invoke the set_robust_list system call directly in fork Florian Weimer via Libc-alpha
2021-04-16  9:22 ` [PATCH v4 19/37] dlfcn: Failures after dlmopen should not terminate process [BZ #24772] Florian Weimer via Libc-alpha
2021-04-16  9:22 ` [PATCH v4 20/37] dlfcn: dlerror needs to call free from the base namespace [BZ #24773] Florian Weimer via Libc-alpha
2021-04-16  9:22 ` [PATCH v4 21/37] Remove pthread_key_create-related internals from libc-lock.h Florian Weimer via Libc-alpha
2021-04-16  9:22 ` [PATCH v4 22/37] elf: Introduce __tls_init_tp for second-phase TCB initialization Florian Weimer via Libc-alpha
2021-04-16  9:22 ` [PATCH v4 23/37] nptl: Move part of TCB initialization from libpthread to __tls_init_tp Florian Weimer via Libc-alpha
2021-04-16  9:22 ` [PATCH v4 24/37] nptl: Move pthread_key_create, __pthread_key_create into libc Florian Weimer via Libc-alpha
2021-04-16  9:23 ` [PATCH v4 25/37] nptl: Move pthread_getspecific, __pthread_getspecific " Florian Weimer via Libc-alpha
2021-04-16  9:23 ` [PATCH v4 26/37] nptl: Move pthread_setspecific, __pthread_setspecific " Florian Weimer via Libc-alpha
2021-04-16  9:23 ` [PATCH v4 27/37] nptl: Move pthread_key_delete " Florian Weimer via Libc-alpha
2021-04-16  9:23 ` [PATCH v4 28/37] nptl: Move rwlock functions with forwarders " Florian Weimer via Libc-alpha
2021-04-16  9:23 ` [PATCH v4 29/37] nptl: Move the internal thread priority protection symbols " Florian Weimer via Libc-alpha
2021-04-16  9:23 ` [PATCH v4 30/37] pthread: Introduce __pthread_early_init Florian Weimer via Libc-alpha
2021-04-16  9:23 ` [PATCH v4 31/37] nptl: Move internal symbol __mutex_aconf into libc Florian Weimer via Libc-alpha
2021-04-16  9:24 ` [PATCH v4 32/37] nptl: pthread_mutex_lock, pthread_mutex_unock single-threaded optimization Florian Weimer via Libc-alpha
2021-04-16  9:24 ` [PATCH v4 33/37] x86: Remove low-level lock optimization Florian Weimer via Libc-alpha
2021-04-16  9:24 ` [PATCH v4 34/37] nptl: Move core mutex functions into libc Florian Weimer via Libc-alpha
2021-04-16  9:24 ` [PATCH v4 35/37] nptl: Move core condition variable " Florian Weimer via Libc-alpha
2021-04-16  9:24 ` [PATCH v4 36/37] nptl: Move setxid broadcast implementation " Florian Weimer via Libc-alpha
2021-04-16  9:24 ` [PATCH v4 37/37] nptl: Remove remnants of the libc/libpthread forwarder interface Florian Weimer via Libc-alpha
2021-04-21 11:47 ` [PATCH v4 00/37] libpthread: Remove NPTL forwarders Florian Weimer via Libc-alpha
2021-04-21 13:42   ` H.J. Lu via Libc-alpha
2021-04-22  7:35   ` Szabolcs Nagy via Libc-alpha
2021-04-22  7:58     ` Florian Weimer via Libc-alpha
2021-04-22  8:56       ` Szabolcs Nagy via Libc-alpha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=db9c649c44812cebda07c3827b638f841f708bbc.1618564630.git.fweimer@redhat.com \
    --to=libc-alpha@sourceware.org \
    --cc=fweimer@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).