]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
htl: Implement some support for TLS_DTV_AT_TP
authorSergey Bugaev <bugaevc@gmail.com>
Sat, 23 Mar 2024 17:32:59 +0000 (20:32 +0300)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sat, 23 Mar 2024 22:00:30 +0000 (23:00 +0100)
Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
Message-ID: <20240323173301.151066-19-bugaevc@gmail.com>

htl/pt-create.c
sysdeps/htl/dl-thread_gscope_wait.c
sysdeps/mach/hurd/htl/pt-sysdep.c

index fac61f1b22d8ada25e7c432e413db074a2e87579..8a735d99cb16d3d9e13f87989b4530f8851ec09d 100644 (file)
@@ -177,7 +177,9 @@ __pthread_create_internal (struct __pthread **thread,
       err = ENOMEM;
       goto failed_thread_tls_alloc;
     }
+#if TLS_TCB_AT_TP
   pthread->tcb->tcb = pthread->tcb;
+#endif
 
   /* And initialize the rest of the machine context.  This may include
      additional machine- and system-specific initializations that
index 90a9a79850c88cd39c7fc1f1083d57223e234310..ee0a3165275c423545d326f3324f0a3dac0e7b57 100644 (file)
 #include <pthread.h>
 #include <htl/pt-internal.h>
 
+static inline int *
+thread_gscope_flag (struct __pthread *t)
+{
+#if TLS_TCB_AT_TP
+  return &t->tcb->gscope_flag;
+#elif TLS_DTV_AT_TP
+  return &((tcbprehead_t *) t->tcb - 1)->gscope_flag;
+#else
+# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
+#endif
+}
+
 void
 __thread_gscope_wait (void)
 {
@@ -33,10 +45,10 @@ __thread_gscope_wait (void)
   for (i = 0; i < GL (dl_pthread_num_threads); ++i)
     {
       t = GL (dl_pthread_threads[i]);
-      if (t == NULL || t->tcb->gscope_flag == THREAD_GSCOPE_FLAG_UNUSED)
+      if (t == NULL || *thread_gscope_flag (t) == THREAD_GSCOPE_FLAG_UNUSED)
         continue;
 
-      gscope_flagp = &t->tcb->gscope_flag;
+      gscope_flagp = thread_gscope_flag (t);
 
       /* We have to wait until this thread is done with the global
          scope.  First tell the thread that we are waiting and
index 270e77531ef3270031a414f824d3189bf3bcf66e..5372cbf77f555d05b742c5aa7509e422e6321232 100644 (file)
@@ -100,7 +100,16 @@ _init_routine (void *stack)
      to the new stack.  Pretend it wasn't allocated so that it remains
      valid if the main thread terminates.  */
   thread->stack = 0;
+#if TLS_TCB_AT_TP
   thread->tcb = THREAD_SELF;
+#elif TLS_DTV_AT_TP
+  /* Assuming THREAD_SELF is implemented as subtracting TLS_PRE_TCB_SIZE
+     from the value of a thread pointer regsiter, this should optimize
+     down to simply reading that register.  */
+  thread->tcb = (tcbhead_t *) (((char *) THREAD_SELF) + TLS_PRE_TCB_SIZE);
+#else
+# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
+#endif
 
 #ifndef PAGESIZE
   __pthread_default_attr.__guardsize = __vm_page_size;