Message ID | 20200114185255.25813-5-samuel.thibault@ens-lyon.org |
---|---|
State | New |
Headers | show |
Series | Port C11 threads to GNU/Hurd | expand |
On 14/01/2020 15:52, Samuel Thibault wrote: > Essentially properly calling the thread function which returns an int > instead of a void*. LGTM, it seems to follow the required nptl changes for Linux. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> > --- > htl/pt-create.c | 20 +++++++++++++++++++- > htl/pt-internal.h | 3 +++ > sysdeps/htl/pthreadP.h | 3 +++ > 3 files changed, 25 insertions(+), 1 deletion(-) > > diff --git a/htl/pt-create.c b/htl/pt-create.c > index 0b3237f46a..090d394f53 100644 > --- a/htl/pt-create.c > +++ b/htl/pt-create.c > @@ -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 Ok. > @@ -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; > Ok. > diff --git a/htl/pt-internal.h b/htl/pt-internal.h > index f8d7d74244..8a45854070 100644 > --- a/htl/pt-internal.h > +++ b/htl/pt-internal.h > @@ -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; > Ok. > diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h > index b1c7575f89..fc8c9bc591 100644 > --- a/sysdeps/htl/pthreadP.h > +++ b/sysdeps/htl/pthreadP.h > @@ -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); > Ok.
diff --git a/htl/pt-create.c b/htl/pt-create.c index 0b3237f46a..090d394f53 100644 --- a/htl/pt-create.c +++ b/htl/pt-create.c @@ -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; diff --git a/htl/pt-internal.h b/htl/pt-internal.h index f8d7d74244..8a45854070 100644 --- a/htl/pt-internal.h +++ b/htl/pt-internal.h @@ -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; diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h index b1c7575f89..fc8c9bc591 100644 --- a/sysdeps/htl/pthreadP.h +++ b/sysdeps/htl/pthreadP.h @@ -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);