about summary refs log tree commit diff
path: root/htl
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2023-08-08 12:19:29 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-08-08 12:19:29 +0200
commit53da64d1cf3694a132287d1ab6e9655031124e32 (patch)
tree348cdf0a18887d4a606e30ee10d76217cfe33092 /htl
parent644aa127b9b42a899a12b6ccc6644bc035c231e3 (diff)
downloadglibc-53da64d1cf3694a132287d1ab6e9655031124e32.tar.gz
glibc-53da64d1cf3694a132287d1ab6e9655031124e32.tar.xz
glibc-53da64d1cf3694a132287d1ab6e9655031124e32.zip
htl: Initialize ___pthread_self early
When using jemalloc, malloc() needs to use TSD, while libpthread
initialization needs malloc(). Having ___pthread_self set early to some
static storage allows TSD to work early, thus allowing jemalloc and
libpthread to initialize together.

This incidentaly simplifies __pthread_enable/disable_asynccancel and
__pthread_self, now that ___pthread_self is always initialized.
Diffstat (limited to 'htl')
-rw-r--r--htl/cancellation.c8
-rw-r--r--htl/pt-self.c10
2 files changed, 1 insertions, 17 deletions
diff --git a/htl/cancellation.c b/htl/cancellation.c
index 9cc61b9f23..5a67083188 100644
--- a/htl/cancellation.c
+++ b/htl/cancellation.c
@@ -25,10 +25,6 @@ int __pthread_enable_asynccancel (void)
   struct __pthread *p = _pthread_self ();
   int oldtype;
 
-  if (___pthread_self == NULL)
-    /* We are not initialized yet, we can't be cancelled anyway.  */
-    return PTHREAD_CANCEL_DEFERRED;
-
   __pthread_mutex_lock (&p->cancel_lock);
   oldtype = p->cancel_type;
   p->cancel_type = PTHREAD_CANCEL_ASYNCHRONOUS;
@@ -43,10 +39,6 @@ void __pthread_disable_asynccancel (int oldtype)
 {
   struct __pthread *p = _pthread_self ();
 
-  if (___pthread_self == NULL)
-    /* We are not initialized yet, we can't be cancelled anyway.  */
-    return;
-
   __pthread_mutex_lock (&p->cancel_lock);
   p->cancel_type = oldtype;
   __pthread_mutex_unlock (&p->cancel_lock);
diff --git a/htl/pt-self.c b/htl/pt-self.c
index f7e9cb88c4..1278908397 100644
--- a/htl/pt-self.c
+++ b/htl/pt-self.c
@@ -24,15 +24,7 @@
 pthread_t
 __pthread_self (void)
 {
-  struct __pthread *self;
-
-  if (___pthread_self == NULL)
-    /* We are not initialized yet, we are the first thread.  */
-    return 1;
-
-  self = _pthread_self ();
-  assert (self != NULL);
-
+  struct __pthread *self = _pthread_self ();
   return self->thread;
 }