]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
htl: Add support for C11 threads behavior
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 13 Jan 2020 20:05:08 +0000 (20:05 +0000)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 9 Feb 2020 12:56:48 +0000 (13:56 +0100)
Essentially properly calling the thread function which returns an int
instead of a void*.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
htl/pt-create.c
htl/pt-internal.h
sysdeps/htl/pthreadP.h

index 0b3237f46a0a4ec09fb7f85640cbba391a271cb5..090d394f53e4d33442cf431109d15c44ff326196 100644 (file)
@@ -59,7 +59,17 @@ entry_point (struct __pthread *self, void *(*start_routine) (void *), void *arg)
 
   __pthread_startup ();
 
-  __pthread_exit (start_routine (arg));
+  if (self->c11)
+    {
+      /* The function pointer of the c11 thread start is cast to an incorrect
+         type on __pthread_create call, however it is casted back to correct
+         one so the call behavior is well-defined (it is assumed that pointers
+         to void are able to represent all values of int).  */
+      int (*start)(void*) = (int (*) (void*)) start_routine;
+      __pthread_exit ((void*) (uintptr_t) start (arg));
+    }
+  else
+    __pthread_exit (start_routine (arg));
 }
 
 /* Create a thread with attributes given by ATTR, executing
@@ -99,6 +109,14 @@ __pthread_create_internal (struct __pthread **thread,
   if (err)
     goto failed;
 
+  if (attr == ATTR_C11_THREAD)
+    {
+      attr = NULL;
+      pthread->c11 = true;
+    }
+  else
+    pthread->c11 = false;
+
   /* Use the default attributes if ATTR is NULL.  */
   setup = attr ? attr : &__pthread_default_attr;
 
index 274223cfe1900ee410e99d5d94747d0210d0a396..9147b87740020d3567bc13f5657cd0f69c8ce6cb 100644 (file)
@@ -100,6 +100,9 @@ struct __pthread
   /* Resolver state.  */
   struct __res_state res_state;
 
+  /* Indicates whether is a C11 thread created by thrd_creat.  */
+  bool c11;
+
   /* Thread context.  */
   struct pthread_mcontext mcontext;
 
index b1c7575f89d7f0aedee97c7be1e96262f26b442b..fc8c9bc59150a79bf28171f3124e37b44a9543e4 100644 (file)
@@ -21,6 +21,9 @@
 
 #include <pthread.h>
 
+/* Attribute to indicate thread creation was issued from C11 thrd_create.  */
+#define ATTR_C11_THREAD ((void*)(uintptr_t)-1)
+
 /* These represent the interface used by glibc itself.  */
 
 extern pthread_t __pthread_self (void);