[PATCH 00/10] Port C11 threads to GNU/Hurd

classic Classic list List threaded Threaded
31 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[PATCH 00/10] Port C11 threads to GNU/Hurd

Samuel Thibault
Hello,

This patch series basiscally moves the C11 threads implementation to
sysdeps/pthread, thus making it available on GNU/Hurd as well.  There
are a few changes that are needed, I'm here proposing them for review,
so we can probably commit them early in the 2.32 development.

Samuel

Samuel Thibault (10):
  htl: Rename _pthread_mutex_init/destroy to __pthread_mutex_init/destroy
  htl: Add missing internal functions declarations
  htl: Add support for C11 threads behavior
  htl: Make __PTHREAD_ONCE_INIT more flexible
  nptl: Move nptl-specific types to separate header
  C11 threads: do not require PTHREAD_DESTRUCTOR_ITERATIONS
  C11 threads: Fix thrd_t / pthread_t compatibility assertion
  C11 threads: make thrd_join more portable
  htl: Add C11 threads types definitions
  C11 threads: Move implementation to sysdeps/pthread

 htl/Versions                                  | 18 ++++++
 htl/pt-create.c                               | 20 +++++-
 htl/pt-initialize.c                           |  4 +-
 htl/pt-internal.h                             |  3 +
 nptl/Makefile                                 | 14 +----
 sysdeps/htl/bits/thread-shared-types.h        | 13 ++++
 .../htl/bits/types/struct___pthread_once.h    |  2 +-
 sysdeps/htl/pt-key.h                          |  2 +-
 sysdeps/htl/pt-mutex-destroy.c                |  5 +-
 sysdeps/htl/pt-mutex-init.c                   |  4 +-
 sysdeps/htl/pt-mutex-timedlock.c              |  1 +
 sysdeps/htl/pthread.h                         |  2 +-
 sysdeps/htl/pthreadP.h                        | 23 ++++++-
 sysdeps/htl/thrd_current.c                    | 31 +++++++++
 sysdeps/htl/threads.h                         |  1 -
 sysdeps/hurd/stdc-predef.h                    | 63 -------------------
 sysdeps/mach/htl/thrd_yield.c                 | 26 ++++++++
 sysdeps/mach/hurd/htl/pt-mutex-destroy.c      |  5 +-
 sysdeps/mach/hurd/htl/pt-mutex-init.c         |  6 +-
 sysdeps/mach/hurd/htl/pt-mutex-timedlock.c    |  1 +
 sysdeps/mach/hurd/i386/libc.abilist           |  4 ++
 sysdeps/mach/hurd/i386/libpthread.abilist     | 23 ++++++-
 sysdeps/nptl/bits/thread-shared-types.h       | 10 +++
 sysdeps/nptl/thrd_create.c                    |  2 +
 sysdeps/pthread/Makefile                      | 18 ++++++
 {nptl => sysdeps/pthread}/call_once.c         |  2 +-
 {nptl => sysdeps/pthread}/cnd_broadcast.c     |  0
 {nptl => sysdeps/pthread}/cnd_destroy.c       |  0
 {nptl => sysdeps/pthread}/cnd_init.c          |  0
 {nptl => sysdeps/pthread}/cnd_signal.c        |  0
 {nptl => sysdeps/pthread}/cnd_timedwait.c     |  0
 {nptl => sysdeps/pthread}/cnd_wait.c          |  0
 {nptl => sysdeps/pthread}/mtx_destroy.c       |  0
 {nptl => sysdeps/pthread}/mtx_init.c          |  0
 {nptl => sysdeps/pthread}/mtx_lock.c          |  0
 {nptl => sysdeps/pthread}/mtx_timedlock.c     |  0
 {nptl => sysdeps/pthread}/mtx_trylock.c       |  0
 {nptl => sysdeps/pthread}/mtx_unlock.c        |  0
 {nptl => sysdeps/pthread}/thrd_create.c       |  8 +--
 {nptl => sysdeps/pthread}/thrd_detach.c       |  0
 {nptl => sysdeps/pthread}/thrd_equal.c        |  0
 {nptl => sysdeps/pthread}/thrd_exit.c         |  0
 {nptl => sysdeps/pthread}/thrd_join.c         |  2 +-
 {nptl => sysdeps/pthread}/thrd_priv.h         |  0
 {nptl => sysdeps/pthread}/thrd_sleep.c        |  0
 sysdeps/{nptl => pthread}/threads.h           | 13 ++--
 {nptl => sysdeps/pthread}/tss_create.c        |  2 +
 {nptl => sysdeps/pthread}/tss_delete.c        |  0
 {nptl => sysdeps/pthread}/tss_get.c           |  0
 {nptl => sysdeps/pthread}/tss_set.c           |  0
 {nptl => sysdeps/pthread}/tst-call-once.c     |  0
 {nptl => sysdeps/pthread}/tst-cnd-basic.c     |  0
 {nptl => sysdeps/pthread}/tst-cnd-broadcast.c |  0
 {nptl => sysdeps/pthread}/tst-cnd-timedwait.c |  0
 {nptl => sysdeps/pthread}/tst-mtx-basic.c     |  0
 {nptl => sysdeps/pthread}/tst-mtx-recursive.c |  0
 {nptl => sysdeps/pthread}/tst-mtx-timedlock.c |  0
 {nptl => sysdeps/pthread}/tst-mtx-trylock.c   |  0
 {nptl => sysdeps/pthread}/tst-thrd-detach.c   |  0
 {nptl => sysdeps/pthread}/tst-thrd-sleep.c    |  0
 {nptl => sysdeps/pthread}/tst-tss-basic.c     |  0
 61 files changed, 220 insertions(+), 108 deletions(-)
 create mode 100644 sysdeps/htl/thrd_current.c
 delete mode 100644 sysdeps/htl/threads.h
 delete mode 100644 sysdeps/hurd/stdc-predef.h
 create mode 100644 sysdeps/mach/htl/thrd_yield.c
 create mode 100644 sysdeps/nptl/thrd_create.c
 rename {nptl => sysdeps/pthread}/call_once.c (95%)
 rename {nptl => sysdeps/pthread}/cnd_broadcast.c (100%)
 rename {nptl => sysdeps/pthread}/cnd_destroy.c (100%)
 rename {nptl => sysdeps/pthread}/cnd_init.c (100%)
 rename {nptl => sysdeps/pthread}/cnd_signal.c (100%)
 rename {nptl => sysdeps/pthread}/cnd_timedwait.c (100%)
 rename {nptl => sysdeps/pthread}/cnd_wait.c (100%)
 rename {nptl => sysdeps/pthread}/mtx_destroy.c (100%)
 rename {nptl => sysdeps/pthread}/mtx_init.c (100%)
 rename {nptl => sysdeps/pthread}/mtx_lock.c (100%)
 rename {nptl => sysdeps/pthread}/mtx_timedlock.c (100%)
 rename {nptl => sysdeps/pthread}/mtx_trylock.c (100%)
 rename {nptl => sysdeps/pthread}/mtx_unlock.c (100%)
 rename {nptl => sysdeps/pthread}/thrd_create.c (82%)
 rename {nptl => sysdeps/pthread}/thrd_detach.c (100%)
 rename {nptl => sysdeps/pthread}/thrd_equal.c (100%)
 rename {nptl => sysdeps/pthread}/thrd_exit.c (100%)
 rename {nptl => sysdeps/pthread}/thrd_join.c (92%)
 rename {nptl => sysdeps/pthread}/thrd_priv.h (100%)
 rename {nptl => sysdeps/pthread}/thrd_sleep.c (100%)
 rename sysdeps/{nptl => pthread}/threads.h (97%)
 rename {nptl => sysdeps/pthread}/tss_create.c (96%)
 rename {nptl => sysdeps/pthread}/tss_delete.c (100%)
 rename {nptl => sysdeps/pthread}/tss_get.c (100%)
 rename {nptl => sysdeps/pthread}/tss_set.c (100%)
 rename {nptl => sysdeps/pthread}/tst-call-once.c (100%)
 rename {nptl => sysdeps/pthread}/tst-cnd-basic.c (100%)
 rename {nptl => sysdeps/pthread}/tst-cnd-broadcast.c (100%)
 rename {nptl => sysdeps/pthread}/tst-cnd-timedwait.c (100%)
 rename {nptl => sysdeps/pthread}/tst-mtx-basic.c (100%)
 rename {nptl => sysdeps/pthread}/tst-mtx-recursive.c (100%)
 rename {nptl => sysdeps/pthread}/tst-mtx-timedlock.c (100%)
 rename {nptl => sysdeps/pthread}/tst-mtx-trylock.c (100%)
 rename {nptl => sysdeps/pthread}/tst-thrd-detach.c (100%)
 rename {nptl => sysdeps/pthread}/tst-thrd-sleep.c (100%)
 rename {nptl => sysdeps/pthread}/tst-tss-basic.c (100%)

--
2.24.1

Reply | Threaded
Open this post in threaded view
|

[hurd,commited] htl: Add internal version of __pthread_mutex_timedlock

Samuel Thibault
The C11 threads implementation will need it.
---
 htl/Versions                               | 1 +
 sysdeps/htl/pt-mutex-timedlock.c           | 3 ++-
 sysdeps/htl/pthreadP.h                     | 2 ++
 sysdeps/mach/hurd/htl/pt-mutex-timedlock.c | 3 ++-
 4 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/htl/Versions b/htl/Versions
index 1c306acf5c..77f7335b9c 100644
--- a/htl/Versions
+++ b/htl/Versions
@@ -155,5 +155,6 @@ libpthread {
     __pthread_setspecific;
     __pthread_getattr_np;
     __pthread_attr_getstack;
+    __pthread_mutex_timedlock;
   }
 }
diff --git a/sysdeps/htl/pt-mutex-timedlock.c b/sysdeps/htl/pt-mutex-timedlock.c
index d0ebb2975e..0e50f38ef2 100644
--- a/sysdeps/htl/pt-mutex-timedlock.c
+++ b/sysdeps/htl/pt-mutex-timedlock.c
@@ -189,8 +189,9 @@ __pthread_mutex_timedlock_internal (struct __pthread_mutex *mutex,
 }
 
 int
-pthread_mutex_timedlock (struct __pthread_mutex *mutex,
+__pthread_mutex_timedlock (struct __pthread_mutex *mutex,
  const struct timespec *abstime)
 {
   return __pthread_mutex_timedlock_internal (mutex, abstime);
 }
+strong_alias (__pthread_mutex_timedlock, pthread_mutex_timedlock)
diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h
index af0154538a..affe7cdf53 100644
--- a/sysdeps/htl/pthreadP.h
+++ b/sysdeps/htl/pthreadP.h
@@ -29,6 +29,8 @@ extern struct __pthread **__pthread_threads;
 
 extern int _pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
 extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
+extern int __pthread_mutex_timedlock (pthread_mutex_t *__mutex,
+     const struct timespec *__abstime);
 extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
 
 extern int __pthread_cond_broadcast (pthread_cond_t *cond);
diff --git a/sysdeps/mach/hurd/htl/pt-mutex-timedlock.c b/sysdeps/mach/hurd/htl/pt-mutex-timedlock.c
index 13136ddfe1..e83bc57875 100644
--- a/sysdeps/mach/hurd/htl/pt-mutex-timedlock.c
+++ b/sysdeps/mach/hurd/htl/pt-mutex-timedlock.c
@@ -24,7 +24,7 @@
 #include <hurdlock.h>
 
 int
-pthread_mutex_timedlock (pthread_mutex_t *mtxp, const struct timespec *tsp)
+__pthread_mutex_timedlock (pthread_mutex_t *mtxp, const struct timespec *tsp)
 {
   struct __pthread *self;
   int ret, flags = mtxp->__flags & GSYNC_SHARED;
@@ -76,3 +76,4 @@ pthread_mutex_timedlock (pthread_mutex_t *mtxp, const struct timespec *tsp)
 
   return ret;
 }
+strong_alias (__pthread_mutex_timedlock, pthread_mutex_timedlock)
--
2.24.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 01/10] htl: Rename _pthread_mutex_init/destroy to __pthread_mutex_init/destroy

Samuel Thibault
In reply to this post by Samuel Thibault
---
 htl/Versions                              | 2 ++
 htl/pt-initialize.c                       | 4 ++--
 sysdeps/htl/pt-key.h                      | 2 +-
 sysdeps/htl/pt-mutex-destroy.c            | 4 ++--
 sysdeps/htl/pt-mutex-init.c               | 4 ++--
 sysdeps/htl/pthreadP.h                    | 5 +++--
 sysdeps/mach/hurd/htl/pt-mutex-destroy.c  | 4 ++--
 sysdeps/mach/hurd/htl/pt-mutex-init.c     | 6 +++---
 sysdeps/mach/hurd/i386/libpthread.abilist | 2 --
 9 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/htl/Versions b/htl/Versions
index 77f7335b9c..3ae4b5c17d 100644
--- a/htl/Versions
+++ b/htl/Versions
@@ -155,6 +155,8 @@ libpthread {
     __pthread_setspecific;
     __pthread_getattr_np;
     __pthread_attr_getstack;
+    __pthread_mutex_init;
+    __pthread_mutex_destroy;
     __pthread_mutex_timedlock;
   }
 }
diff --git a/htl/pt-initialize.c b/htl/pt-initialize.c
index d5a64f7cd9..89ed742422 100644
--- a/htl/pt-initialize.c
+++ b/htl/pt-initialize.c
@@ -51,8 +51,8 @@ static const struct pthread_functions pthread_functions = {
   .ptr___pthread_exit = __pthread_exit,
   .ptr_pthread_getschedparam = __pthread_getschedparam,
   .ptr_pthread_setschedparam = __pthread_setschedparam,
-  .ptr_pthread_mutex_destroy = _pthread_mutex_destroy,
-  .ptr_pthread_mutex_init = _pthread_mutex_init,
+  .ptr_pthread_mutex_destroy = __pthread_mutex_destroy,
+  .ptr_pthread_mutex_init = __pthread_mutex_init,
   .ptr_pthread_mutex_lock = __pthread_mutex_lock,
   .ptr_pthread_mutex_trylock = __pthread_mutex_trylock,
   .ptr_pthread_mutex_unlock = __pthread_mutex_unlock,
diff --git a/sysdeps/htl/pt-key.h b/sysdeps/htl/pt-key.h
index bfaa19900a..b547e8ad29 100644
--- a/sysdeps/htl/pt-key.h
+++ b/sysdeps/htl/pt-key.h
@@ -66,7 +66,7 @@ __pthread_key_lock_ready (void)
     err = __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
     assert_perror (err);
 
-    err = _pthread_mutex_init (&__pthread_key_lock, &attr);
+    err = __pthread_mutex_init (&__pthread_key_lock, &attr);
     assert_perror (err);
 
     err = __pthread_mutexattr_destroy (&attr);
diff --git a/sysdeps/htl/pt-mutex-destroy.c b/sysdeps/htl/pt-mutex-destroy.c
index 3824e62dd4..796fc11b8d 100644
--- a/sysdeps/htl/pt-mutex-destroy.c
+++ b/sysdeps/htl/pt-mutex-destroy.c
@@ -23,7 +23,7 @@
 #include <pt-internal.h>
 
 int
-_pthread_mutex_destroy (pthread_mutex_t *mutex)
+__pthread_mutex_destroy (pthread_mutex_t *mutex)
 {
   if (mutex->__attr == __PTHREAD_ERRORCHECK_MUTEXATTR
       || mutex->__attr == __PTHREAD_RECURSIVE_MUTEXATTR)
@@ -35,4 +35,4 @@ _pthread_mutex_destroy (pthread_mutex_t *mutex)
   return 0;
 }
 
-strong_alias (_pthread_mutex_destroy, pthread_mutex_destroy);
+strong_alias (__pthread_mutex_destroy, pthread_mutex_destroy);
diff --git a/sysdeps/htl/pt-mutex-init.c b/sysdeps/htl/pt-mutex-init.c
index c59bd8a3f5..77f041352e 100644
--- a/sysdeps/htl/pt-mutex-init.c
+++ b/sysdeps/htl/pt-mutex-init.c
@@ -24,7 +24,7 @@
 #include <pt-internal.h>
 
 int
-_pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
+__pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
 {
   *mutex = (pthread_mutex_t) __PTHREAD_MUTEX_INITIALIZER;
 
@@ -47,4 +47,4 @@ _pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
   return 0;
 }
 
-strong_alias (_pthread_mutex_init, pthread_mutex_init);
+strong_alias (__pthread_mutex_init, pthread_mutex_init);
diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h
index affe7cdf53..c6ddf76fd4 100644
--- a/sysdeps/htl/pthreadP.h
+++ b/sysdeps/htl/pthreadP.h
@@ -27,7 +27,8 @@ extern pthread_t __pthread_self (void);
 extern int __pthread_kill (pthread_t threadid, int signo);
 extern struct __pthread **__pthread_threads;
 
-extern int _pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
+extern int __pthread_mutex_init (pthread_mutex_t *__mutex, const pthread_mutexattr_t *__attr);
+extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
 extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
 extern int __pthread_mutex_timedlock (pthread_mutex_t *__mutex,
      const struct timespec *__abstime);
@@ -73,7 +74,7 @@ struct __pthread_cancelation_handler **___pthread_get_cleanup_stack (void) attri
 hidden_proto (__pthread_key_create)
 hidden_proto (__pthread_getspecific)
 hidden_proto (__pthread_setspecific)
-hidden_proto (_pthread_mutex_init)
+hidden_proto (__pthread_mutex_init)
 #endif
 
 #define ASSERT_TYPE_SIZE(type, size) \
diff --git a/sysdeps/mach/hurd/htl/pt-mutex-destroy.c b/sysdeps/mach/hurd/htl/pt-mutex-destroy.c
index afab03234e..a8a0adc03f 100644
--- a/sysdeps/mach/hurd/htl/pt-mutex-destroy.c
+++ b/sysdeps/mach/hurd/htl/pt-mutex-destroy.c
@@ -24,7 +24,7 @@
 #include <hurdlock.h>
 
 int
-_pthread_mutex_destroy (pthread_mutex_t *mtxp)
+__pthread_mutex_destroy (pthread_mutex_t *mtxp)
 {
   atomic_read_barrier ();
   if (*(volatile unsigned int *) &mtxp->__lock != 0)
@@ -34,4 +34,4 @@ _pthread_mutex_destroy (pthread_mutex_t *mtxp)
   return 0;
 }
 
-strong_alias (_pthread_mutex_destroy, pthread_mutex_destroy)
+strong_alias (__pthread_mutex_destroy, pthread_mutex_destroy)
diff --git a/sysdeps/mach/hurd/htl/pt-mutex-init.c b/sysdeps/mach/hurd/htl/pt-mutex-init.c
index 6b804116a5..7a2cc462f3 100644
--- a/sysdeps/mach/hurd/htl/pt-mutex-init.c
+++ b/sysdeps/mach/hurd/htl/pt-mutex-init.c
@@ -32,7 +32,7 @@ static const pthread_mutexattr_t dfl_attr = {
 };
 
 int
-_pthread_mutex_init (pthread_mutex_t *mtxp, const pthread_mutexattr_t *attrp)
+__pthread_mutex_init (pthread_mutex_t *mtxp, const pthread_mutexattr_t *attrp)
 {
   ASSERT_TYPE_SIZE (pthread_mutex_t, __SIZEOF_PTHREAD_MUTEX_T);
 
@@ -55,5 +55,5 @@ _pthread_mutex_init (pthread_mutex_t *mtxp, const pthread_mutexattr_t *attrp)
   return 0;
 }
 
-strong_alias (_pthread_mutex_init, pthread_mutex_init)
-hidden_def (_pthread_mutex_init)
+strong_alias (__pthread_mutex_init, pthread_mutex_init)
+hidden_def (__pthread_mutex_init)
diff --git a/sysdeps/mach/hurd/i386/libpthread.abilist b/sysdeps/mach/hurd/i386/libpthread.abilist
index 0ede90859c..cda8755960 100644
--- a/sysdeps/mach/hurd/i386/libpthread.abilist
+++ b/sysdeps/mach/hurd/i386/libpthread.abilist
@@ -14,8 +14,6 @@ GLIBC_2.12 _cthread_init_routine D 0x4
 GLIBC_2.12 _cthreads_flockfile F
 GLIBC_2.12 _cthreads_ftrylockfile F
 GLIBC_2.12 _cthreads_funlockfile F
-GLIBC_2.12 _pthread_mutex_destroy F
-GLIBC_2.12 _pthread_mutex_init F
 GLIBC_2.12 _pthread_mutex_lock F
 GLIBC_2.12 _pthread_mutex_trylock F
 GLIBC_2.12 _pthread_mutex_unlock F
--
2.24.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 02/10] htl: Add missing internal functions declarations

Samuel Thibault
In reply to this post by Samuel Thibault
---
 sysdeps/htl/pthreadP.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h
index c6ddf76fd4..b1c7575f89 100644
--- a/sysdeps/htl/pthreadP.h
+++ b/sysdeps/htl/pthreadP.h
@@ -30,11 +30,22 @@ extern struct __pthread **__pthread_threads;
 extern int __pthread_mutex_init (pthread_mutex_t *__mutex, const pthread_mutexattr_t *__attr);
 extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
 extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
+extern int __pthread_mutex_trylock (pthread_mutex_t *_mutex);
 extern int __pthread_mutex_timedlock (pthread_mutex_t *__mutex,
      const struct timespec *__abstime);
 extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
+extern int __pthread_mutexattr_init (pthread_mutexattr_t *attr);
+extern int __pthread_mutexattr_settype (pthread_mutexattr_t *attr, int kind);
 
+extern int __pthread_cond_init (pthread_cond_t *cond,
+ const pthread_condattr_t *cond_attr);
+extern int __pthread_cond_signal (pthread_cond_t *cond);
 extern int __pthread_cond_broadcast (pthread_cond_t *cond);
+extern int __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex);
+extern int __pthread_cond_timedwait (pthread_cond_t *cond,
+     pthread_mutex_t *mutex,
+     const struct timespec *abstime);
+extern int __pthread_cond_destroy (pthread_cond_t *cond);
 
 typedef struct __cthread *__cthread_t;
 typedef int __cthread_key_t;
@@ -55,6 +66,8 @@ int __cthread_setspecific (__cthread_key_t, void *);
 int __pthread_key_create (pthread_key_t *key, void (*destr) (void *));
 void *__pthread_getspecific (pthread_key_t key);
 int __pthread_setspecific (pthread_key_t key, const void *value);
+int __pthread_key_delete (pthread_key_t key);
+int __pthread_once (pthread_once_t *once_control, void (*init_routine) (void));
 
 int __pthread_setcancelstate (int state, int *oldstate);
 
--
2.24.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 03/10] htl: Add support for C11 threads behavior

Samuel Thibault
In reply to this post by Samuel Thibault
Essentially properly calling the thread function which returns an int
instead of a void*.
---
 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
@@ -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);
--
2.24.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 04/10] htl: Make __PTHREAD_ONCE_INIT more flexible

Samuel Thibault
In reply to this post by Samuel Thibault
by moving its (struct __pthread_once) cast into PTHREAD_ONCE_INIT.
---
 sysdeps/htl/bits/types/struct___pthread_once.h | 2 +-
 sysdeps/htl/pthread.h                          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sysdeps/htl/bits/types/struct___pthread_once.h b/sysdeps/htl/bits/types/struct___pthread_once.h
index 31a0c0817b..a6b6db708c 100644
--- a/sysdeps/htl/bits/types/struct___pthread_once.h
+++ b/sysdeps/htl/bits/types/struct___pthread_once.h
@@ -28,6 +28,6 @@ struct __pthread_once
 };
 
 #define __PTHREAD_ONCE_INIT \
- (struct __pthread_once) { 0, __PTHREAD_SPIN_LOCK_INITIALIZER }
+ 0, __PTHREAD_SPIN_LOCK_INITIALIZER
 
 #endif /* bits/types/struct___pthread_once.h */
diff --git a/sysdeps/htl/pthread.h b/sysdeps/htl/pthread.h
index 3216860493..38c61e8da3 100644
--- a/sysdeps/htl/pthread.h
+++ b/sysdeps/htl/pthread.h
@@ -802,7 +802,7 @@ extern int pthread_setspecific (pthread_key_t __key, const void *__value)
 
 #include <bits/types/struct___pthread_once.h>
 
-#define PTHREAD_ONCE_INIT __PTHREAD_ONCE_INIT
+#define PTHREAD_ONCE_INIT (struct __pthread_once) { __PTHREAD_ONCE_INIT }
 
 /* Call INIT_ROUTINE if this function has never been called with
    *ONCE_CONTROL, otherwise do nothing.  */
--
2.24.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 05/10] nptl: Move nptl-specific types to separate header

Samuel Thibault
In reply to this post by Samuel Thibault
---
 nptl/call_once.c                        |  2 +-
 sysdeps/nptl/bits/thread-shared-types.h | 10 ++++++++++
 sysdeps/nptl/threads.h                  | 13 +++++--------
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/nptl/call_once.c b/nptl/call_once.c
index 3f880a9073..25e2964c76 100644
--- a/nptl/call_once.c
+++ b/nptl/call_once.c
@@ -27,5 +27,5 @@ call_once (once_flag *flag, void (*func)(void))
   "sizeof (once_flag) != sizeof (pthread_once_t)");
   _Static_assert (alignof (once_flag) == alignof (pthread_once_t),
   "alignof (once_flag) != alignof (pthread_once_t)");
-  __pthread_once (&flag->__data, func);
+  __pthread_once ((pthread_once_t *) flag, func);
 }
diff --git a/sysdeps/nptl/bits/thread-shared-types.h b/sysdeps/nptl/bits/thread-shared-types.h
index fd08b6916a..fbbdd0bb36 100644
--- a/sysdeps/nptl/bits/thread-shared-types.h
+++ b/sysdeps/nptl/bits/thread-shared-types.h
@@ -116,4 +116,14 @@ struct __pthread_cond_s
   unsigned int __g_signals[2];
 };
 
+typedef unsigned int __tss_t;
+typedef unsigned long int __thrd_t;
+
+typedef struct
+{
+  int __data __ONCE_ALIGNMENT;
+} __once_flag;
+
+#define __ONCE_FLAG_INIT { 0 }
+
 #endif /* _THREAD_SHARED_TYPES_H  */
diff --git a/sysdeps/nptl/threads.h b/sysdeps/nptl/threads.h
index 6d5e4bfe02..0ac489b4a1 100644
--- a/sysdeps/nptl/threads.h
+++ b/sysdeps/nptl/threads.h
@@ -24,7 +24,7 @@
 
 __BEGIN_DECLS
 
-#include <bits/pthreadtypes-arch.h>
+#include <bits/thread-shared-types.h>
 #include <bits/types/struct_timespec.h>
 
 #ifndef __cplusplus
@@ -32,10 +32,10 @@ __BEGIN_DECLS
 #endif
 
 #define TSS_DTOR_ITERATIONS 4
-typedef unsigned int tss_t;
+typedef __tss_t tss_t;
 typedef void (*tss_dtor_t) (void*);
 
-typedef unsigned long int thrd_t;
+typedef __thrd_t thrd_t;
 typedef int (*thrd_start_t) (void*);
 
 /* Exit and error codes.  */
@@ -56,11 +56,8 @@ enum
   mtx_timed     = 2
 };
 
-typedef struct
-{
-  int __data __ONCE_ALIGNMENT;
-} once_flag;
-#define ONCE_FLAG_INIT { 0 }
+typedef __once_flag once_flag;
+#define ONCE_FLAG_INIT __ONCE_FLAG_INIT
 
 typedef union
 {
--
2.24.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 06/10] C11 threads: do not require PTHREAD_DESTRUCTOR_ITERATIONS

Samuel Thibault
In reply to this post by Samuel Thibault
It is optional in POSIX.
---
 nptl/tss_create.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/nptl/tss_create.c b/nptl/tss_create.c
index ea1f2e0fba..4e170dd4fc 100644
--- a/nptl/tss_create.c
+++ b/nptl/tss_create.c
@@ -23,8 +23,10 @@ tss_create (tss_t *tss_id, tss_dtor_t destructor)
 {
   _Static_assert (sizeof (tss_t) == sizeof (pthread_key_t),
   "sizeof (tss_t) != sizeof (pthread_key_t)");
+#ifdef PTHREAD_DESTRUCTOR_ITERATIONS
   _Static_assert (TSS_DTOR_ITERATIONS == PTHREAD_DESTRUCTOR_ITERATIONS,
   "TSS_DTOR_ITERATIONS != PTHREAD_DESTRUCTOR_ITERATIONS");
+#endif
 
   int err_code = __pthread_key_create (tss_id, destructor);
   return thrd_err_map (err_code);
--
2.24.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 07/10] C11 threads: Fix thrd_t / pthread_t compatibility assertion

Samuel Thibault
In reply to this post by Samuel Thibault
---
 nptl/thrd_create.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/nptl/thrd_create.c b/nptl/thrd_create.c
index 8474e234c9..fe08e22973 100644
--- a/nptl/thrd_create.c
+++ b/nptl/thrd_create.c
@@ -21,8 +21,8 @@
 int
 thrd_create (thrd_t *thr, thrd_start_t func, void *arg)
 {
-  _Static_assert (sizeof (thr) == sizeof (pthread_t),
-  "sizeof (thr) != sizeof (pthread_t)");
+  _Static_assert (sizeof (*thr) == sizeof (pthread_t),
+  "sizeof (*thr) != sizeof (pthread_t)");
 
   int err_code = __pthread_create_2_1 (thr, ATTR_C11_THREAD,
        (void* (*) (void*))func, arg);
--
2.24.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 08/10] C11 threads: make thrd_join more portable

Samuel Thibault
In reply to this post by Samuel Thibault
by making a __pthread_join call instead of an equivalent __pthread_clockjoin_ex
call.
---
 nptl/thrd_join.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nptl/thrd_join.c b/nptl/thrd_join.c
index 783e36f02b..0c482959d5 100644
--- a/nptl/thrd_join.c
+++ b/nptl/thrd_join.c
@@ -22,7 +22,7 @@ int
 thrd_join (thrd_t thr, int *res)
 {
   void *pthread_res;
-  int err_code = __pthread_clockjoin_ex (thr, &pthread_res, 0, NULL, true);
+  int err_code = __pthread_join (thr, &pthread_res);
   if (res)
    *res = (int) (uintptr_t) pthread_res;
 
--
2.24.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 09/10] htl: Add C11 threads types definitions

Samuel Thibault
In reply to this post by Samuel Thibault
---
 sysdeps/htl/bits/thread-shared-types.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/sysdeps/htl/bits/thread-shared-types.h b/sysdeps/htl/bits/thread-shared-types.h
index c280f2e182..819682a07b 100644
--- a/sysdeps/htl/bits/thread-shared-types.h
+++ b/sysdeps/htl/bits/thread-shared-types.h
@@ -20,5 +20,18 @@
 #define _THREAD_SHARED_TYPES_H 1
 
 #include <bits/pthreadtypes-arch.h>
+#include <bits/types/struct___pthread_once.h>
+
+typedef int __tss_t;
+typedef int __thrd_t;
+
+typedef union
+{
+  struct __pthread_once __data;
+  int __align __ONCE_ALIGNMENT;
+  char __size[__SIZEOF_PTHREAD_ONCE_T];
+} __once_flag;
+
+#define __ONCE_FLAG_INIT { { __PTHREAD_ONCE_INIT } }
 
 #endif /* _THREAD_SHARED_TYPES_H  */
--
2.24.1

Reply | Threaded
Open this post in threaded view
|

[PATCH 10/10] C11 threads: Move implementation to sysdeps/pthread

Samuel Thibault
In reply to this post by Samuel Thibault
so it gets shared by nptl and htl. Also add htl versions of thrd_current and
thrd_yield.
---
 htl/Versions                                  | 16 +++++
 nptl/Makefile                                 | 14 +----
 sysdeps/htl/pt-mutex-destroy.c                |  1 +
 sysdeps/htl/pt-mutex-timedlock.c              |  1 +
 sysdeps/htl/pthreadP.h                        |  2 +
 sysdeps/htl/thrd_current.c                    | 31 +++++++++
 sysdeps/htl/threads.h                         |  1 -
 sysdeps/hurd/stdc-predef.h                    | 63 -------------------
 sysdeps/mach/htl/thrd_yield.c                 | 26 ++++++++
 sysdeps/mach/hurd/htl/pt-mutex-destroy.c      |  1 +
 sysdeps/mach/hurd/htl/pt-mutex-timedlock.c    |  1 +
 sysdeps/mach/hurd/i386/libc.abilist           |  4 ++
 sysdeps/mach/hurd/i386/libpthread.abilist     | 21 +++++++
 sysdeps/nptl/thrd_create.c                    |  2 +
 sysdeps/pthread/Makefile                      | 18 ++++++
 {nptl => sysdeps/pthread}/call_once.c         |  0
 {nptl => sysdeps/pthread}/cnd_broadcast.c     |  0
 {nptl => sysdeps/pthread}/cnd_destroy.c       |  0
 {nptl => sysdeps/pthread}/cnd_init.c          |  0
 {nptl => sysdeps/pthread}/cnd_signal.c        |  0
 {nptl => sysdeps/pthread}/cnd_timedwait.c     |  0
 {nptl => sysdeps/pthread}/cnd_wait.c          |  0
 {nptl => sysdeps/pthread}/mtx_destroy.c       |  0
 {nptl => sysdeps/pthread}/mtx_init.c          |  0
 {nptl => sysdeps/pthread}/mtx_lock.c          |  0
 {nptl => sysdeps/pthread}/mtx_timedlock.c     |  0
 {nptl => sysdeps/pthread}/mtx_trylock.c       |  0
 {nptl => sysdeps/pthread}/mtx_unlock.c        |  0
 {nptl => sysdeps/pthread}/thrd_create.c       |  4 +-
 {nptl => sysdeps/pthread}/thrd_detach.c       |  0
 {nptl => sysdeps/pthread}/thrd_equal.c        |  0
 {nptl => sysdeps/pthread}/thrd_exit.c         |  0
 {nptl => sysdeps/pthread}/thrd_join.c         |  0
 {nptl => sysdeps/pthread}/thrd_priv.h         |  0
 {nptl => sysdeps/pthread}/thrd_sleep.c        |  0
 sysdeps/{nptl => pthread}/threads.h           |  0
 {nptl => sysdeps/pthread}/tss_create.c        |  0
 {nptl => sysdeps/pthread}/tss_delete.c        |  0
 {nptl => sysdeps/pthread}/tss_get.c           |  0
 {nptl => sysdeps/pthread}/tss_set.c           |  0
 {nptl => sysdeps/pthread}/tst-call-once.c     |  0
 {nptl => sysdeps/pthread}/tst-cnd-basic.c     |  0
 {nptl => sysdeps/pthread}/tst-cnd-broadcast.c |  0
 {nptl => sysdeps/pthread}/tst-cnd-timedwait.c |  0
 {nptl => sysdeps/pthread}/tst-mtx-basic.c     |  0
 {nptl => sysdeps/pthread}/tst-mtx-recursive.c |  0
 {nptl => sysdeps/pthread}/tst-mtx-timedlock.c |  0
 {nptl => sysdeps/pthread}/tst-mtx-trylock.c   |  0
 {nptl => sysdeps/pthread}/tst-thrd-detach.c   |  0
 {nptl => sysdeps/pthread}/tst-thrd-sleep.c    |  0
 {nptl => sysdeps/pthread}/tst-tss-basic.c     |  0
 51 files changed, 129 insertions(+), 77 deletions(-)
 create mode 100644 sysdeps/htl/thrd_current.c
 delete mode 100644 sysdeps/htl/threads.h
 delete mode 100644 sysdeps/hurd/stdc-predef.h
 create mode 100644 sysdeps/mach/htl/thrd_yield.c
 create mode 100644 sysdeps/nptl/thrd_create.c
 rename {nptl => sysdeps/pthread}/call_once.c (100%)
 rename {nptl => sysdeps/pthread}/cnd_broadcast.c (100%)
 rename {nptl => sysdeps/pthread}/cnd_destroy.c (100%)
 rename {nptl => sysdeps/pthread}/cnd_init.c (100%)
 rename {nptl => sysdeps/pthread}/cnd_signal.c (100%)
 rename {nptl => sysdeps/pthread}/cnd_timedwait.c (100%)
 rename {nptl => sysdeps/pthread}/cnd_wait.c (100%)
 rename {nptl => sysdeps/pthread}/mtx_destroy.c (100%)
 rename {nptl => sysdeps/pthread}/mtx_init.c (100%)
 rename {nptl => sysdeps/pthread}/mtx_lock.c (100%)
 rename {nptl => sysdeps/pthread}/mtx_timedlock.c (100%)
 rename {nptl => sysdeps/pthread}/mtx_trylock.c (100%)
 rename {nptl => sysdeps/pthread}/mtx_unlock.c (100%)
 rename {nptl => sysdeps/pthread}/thrd_create.c (91%)
 rename {nptl => sysdeps/pthread}/thrd_detach.c (100%)
 rename {nptl => sysdeps/pthread}/thrd_equal.c (100%)
 rename {nptl => sysdeps/pthread}/thrd_exit.c (100%)
 rename {nptl => sysdeps/pthread}/thrd_join.c (100%)
 rename {nptl => sysdeps/pthread}/thrd_priv.h (100%)
 rename {nptl => sysdeps/pthread}/thrd_sleep.c (100%)
 rename sysdeps/{nptl => pthread}/threads.h (100%)
 rename {nptl => sysdeps/pthread}/tss_create.c (100%)
 rename {nptl => sysdeps/pthread}/tss_delete.c (100%)
 rename {nptl => sysdeps/pthread}/tss_get.c (100%)
 rename {nptl => sysdeps/pthread}/tss_set.c (100%)
 rename {nptl => sysdeps/pthread}/tst-call-once.c (100%)
 rename {nptl => sysdeps/pthread}/tst-cnd-basic.c (100%)
 rename {nptl => sysdeps/pthread}/tst-cnd-broadcast.c (100%)
 rename {nptl => sysdeps/pthread}/tst-cnd-timedwait.c (100%)
 rename {nptl => sysdeps/pthread}/tst-mtx-basic.c (100%)
 rename {nptl => sysdeps/pthread}/tst-mtx-recursive.c (100%)
 rename {nptl => sysdeps/pthread}/tst-mtx-timedlock.c (100%)
 rename {nptl => sysdeps/pthread}/tst-mtx-trylock.c (100%)
 rename {nptl => sysdeps/pthread}/tst-thrd-detach.c (100%)
 rename {nptl => sysdeps/pthread}/tst-thrd-sleep.c (100%)
 rename {nptl => sysdeps/pthread}/tst-tss-basic.c (100%)

diff --git a/htl/Versions b/htl/Versions
index 3ae4b5c17d..c44507c21d 100644
--- a/htl/Versions
+++ b/htl/Versions
@@ -20,6 +20,12 @@ libc {
   GLIBC_2.22 {
     __register_atfork;
   }
+
+  # C11 thread symbols.
+  GLIBC_2.32 {
+    thrd_current; thrd_equal; thrd_sleep; thrd_yield;
+  }
+
   GLIBC_PRIVATE {
     __libc_alloca_cutoff;
     __libc_pthread_init;
@@ -142,6 +148,16 @@ libpthread {
     pthread_hurd_cond_wait_np;
     pthread_hurd_cond_timedwait_np;
   }
+
+  # C11 thread symbols.
+  GLIBC_2.32 {
+    thrd_create; thrd_detach; thrd_exit; thrd_join;
+    mtx_init; mtx_lock; mtx_timedlock; mtx_trylock; mtx_unlock; mtx_destroy;
+    call_once;
+    cnd_broadcast; cnd_destroy; cnd_init; cnd_signal; cnd_timedwait; cnd_wait;
+    tss_create; tss_delete; tss_get; tss_set;
+  }
+
   GLIBC_PRIVATE {
     __shm_directory;
     __pthread_threads;
diff --git a/nptl/Makefile b/nptl/Makefile
index 584e0ffd96..820b757692 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -22,7 +22,7 @@ subdir := nptl
 
 include ../Makeconfig
 
-headers := pthread.h semaphore.h bits/semaphore.h threads.h \
+headers := pthread.h semaphore.h bits/semaphore.h \
    bits/struct_mutex.h bits/struct_rwlock.h
 
 extra-libs := libpthread
@@ -30,8 +30,7 @@ extra-libs-others := $(extra-libs)
 
 routines = alloca_cutoff forward libc-lowlevellock libc-cancellation \
    libc-cleanup libc_pthread_init libc_multiple_threads \
-   register-atfork pthread_atfork pthread_self thrd_current \
-   thrd_equal thrd_sleep thrd_yield pthread_equal \
+   register-atfork pthread_atfork pthread_self pthread_equal \
    pthread_attr_destroy pthread_attr_init pthread_attr_getdetachstate \
    pthread_attr_setdetachstate pthread_attr_getinheritsched \
    pthread_attr_setinheritsched pthread_attr_getschedparam \
@@ -141,11 +140,7 @@ libpthread-routines = nptl-init nptlfreeres vars events version pt-interp \
       pthread_mutex_setprioceiling \
       pthread_setname pthread_getname \
       pthread_setattr_default_np pthread_getattr_default_np \
-      thrd_create thrd_detach thrd_exit thrd_join \
-      mtx_destroy mtx_init mtx_lock mtx_timedlock \
-      mtx_trylock mtx_unlock call_once cnd_broadcast \
-      cnd_destroy cnd_init cnd_signal cnd_timedwait cnd_wait \
-      tss_create tss_delete tss_get tss_set pthread_mutex_conf \
+      pthread_mutex_conf \
       libpthread-compat
 #      pthread_setuid pthread_seteuid pthread_setreuid \
 #      pthread_setresuid \
@@ -319,9 +314,6 @@ tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \
  tst-robust-fork tst-create-detached tst-memstream \
  tst-thread-exit-clobber tst-minstack-cancel tst-minstack-exit \
  tst-minstack-throw \
- tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \
- tst-cnd-timedwait tst-thrd-detach tst-mtx-basic tst-thrd-sleep \
- tst-mtx-recursive tst-tss-basic tst-call-once tst-mtx-timedlock \
  tst-rwlock-pwn \
  tst-rwlock-tryrdlock-stall tst-rwlock-trywrlock-stall \
  tst-unwind-thread
diff --git a/sysdeps/htl/pt-mutex-destroy.c b/sysdeps/htl/pt-mutex-destroy.c
index 796fc11b8d..6a3b5be874 100644
--- a/sysdeps/htl/pt-mutex-destroy.c
+++ b/sysdeps/htl/pt-mutex-destroy.c
@@ -36,3 +36,4 @@ __pthread_mutex_destroy (pthread_mutex_t *mutex)
 }
 
 strong_alias (__pthread_mutex_destroy, pthread_mutex_destroy);
+hidden_def (__pthread_mutex_destroy)
diff --git a/sysdeps/htl/pt-mutex-timedlock.c b/sysdeps/htl/pt-mutex-timedlock.c
index 0e50f38ef2..81013984a6 100644
--- a/sysdeps/htl/pt-mutex-timedlock.c
+++ b/sysdeps/htl/pt-mutex-timedlock.c
@@ -195,3 +195,4 @@ __pthread_mutex_timedlock (struct __pthread_mutex *mutex,
   return __pthread_mutex_timedlock_internal (mutex, abstime);
 }
 strong_alias (__pthread_mutex_timedlock, pthread_mutex_timedlock)
+hidden_def (__pthread_mutex_timedlock)
diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h
index fc8c9bc591..fd1e697e39 100644
--- a/sysdeps/htl/pthreadP.h
+++ b/sysdeps/htl/pthreadP.h
@@ -91,6 +91,8 @@ hidden_proto (__pthread_key_create)
 hidden_proto (__pthread_getspecific)
 hidden_proto (__pthread_setspecific)
 hidden_proto (__pthread_mutex_init)
+hidden_proto (__pthread_mutex_destroy)
+hidden_proto (__pthread_mutex_timedlock)
 #endif
 
 #define ASSERT_TYPE_SIZE(type, size) \
diff --git a/sysdeps/htl/thrd_current.c b/sysdeps/htl/thrd_current.c
new file mode 100644
index 0000000000..efc0d11b5d
--- /dev/null
+++ b/sysdeps/htl/thrd_current.c
@@ -0,0 +1,31 @@
+/* C11 threads current thread implementation.
+   Copyright (C) 2018-2020 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 "thrd_priv.h"
+
+#pragma weak __pthread_self
+#pragma weak __pthread_threads
+
+thrd_t
+thrd_current (void)
+{
+  if (__pthread_threads)
+    return (thrd_t) __pthread_self ();
+
+  return (thrd_t) 0;
+}
diff --git a/sysdeps/htl/threads.h b/sysdeps/htl/threads.h
deleted file mode 100644
index 3c04fbcc79..0000000000
--- a/sysdeps/htl/threads.h
+++ /dev/null
@@ -1 +0,0 @@
-#error "HTL does not implement ISO C threads"
diff --git a/sysdeps/hurd/stdc-predef.h b/sysdeps/hurd/stdc-predef.h
deleted file mode 100644
index a7bb5f7c5f..0000000000
--- a/sysdeps/hurd/stdc-predef.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* Copyright (C) 2018-2020 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/>.  */
-
-#ifndef _STDC_PREDEF_H
-#define _STDC_PREDEF_H 1
-
-/* This header is separate from features.h so that the compiler can
-   include it implicitly at the start of every compilation.  It must
-   not itself include <features.h> or any other header that includes
-   <features.h> because the implicit include comes before any feature
-   test macros that may be defined in a source file before it first
-   explicitly includes a system header.  GCC knows the name of this
-   header in order to preinclude it.  */
-
-/* glibc's intent is to support the IEC 559 math functionality, real
-   and complex.  If the GCC (4.9 and later) predefined macros
-   specifying compiler intent are available, use them to determine
-   whether the overall intent is to support these features; otherwise,
-   presume an older compiler has intent to support these features and
-   define these macros by default.  */
-
-#ifdef __GCC_IEC_559
-# if __GCC_IEC_559 > 0
-#  define __STDC_IEC_559__ 1
-# endif
-#else
-# define __STDC_IEC_559__ 1
-#endif
-
-#ifdef __GCC_IEC_559_COMPLEX
-# if __GCC_IEC_559_COMPLEX > 0
-#  define __STDC_IEC_559_COMPLEX__ 1
-# endif
-#else
-# define __STDC_IEC_559_COMPLEX__ 1
-#endif
-
-/* wchar_t uses Unicode 10.0.0.  Version 10.0 of the Unicode Standard is
-   synchronized with ISO/IEC 10646:2017, fifth edition, plus
-   the following additions from Amendment 1 to the fifth edition:
-   - 56 emoji characters
-   - 285 hentaigana
-   - 3 additional Zanabazar Square characters */
-#define __STDC_ISO_10646__ 201706L
-
-/* We do not support C11 <threads.h>.  */
-#define __STDC_NO_THREADS__ 1
-
-#endif
diff --git a/sysdeps/mach/htl/thrd_yield.c b/sysdeps/mach/htl/thrd_yield.c
new file mode 100644
index 0000000000..09e218cf2e
--- /dev/null
+++ b/sysdeps/mach/htl/thrd_yield.c
@@ -0,0 +1,26 @@
+/* sched_yield -- yield the processor.  Mach version.
+   Copyright (C) 2000-2020 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 <mach.h>
+#include "thrd_priv.h"
+
+void
+thrd_yield (void)
+{
+  (void) __swtch ();
+}
diff --git a/sysdeps/mach/hurd/htl/pt-mutex-destroy.c b/sysdeps/mach/hurd/htl/pt-mutex-destroy.c
index a8a0adc03f..a5bfaddcb2 100644
--- a/sysdeps/mach/hurd/htl/pt-mutex-destroy.c
+++ b/sysdeps/mach/hurd/htl/pt-mutex-destroy.c
@@ -35,3 +35,4 @@ __pthread_mutex_destroy (pthread_mutex_t *mtxp)
 }
 
 strong_alias (__pthread_mutex_destroy, pthread_mutex_destroy)
+hidden_def (__pthread_mutex_destroy)
diff --git a/sysdeps/mach/hurd/htl/pt-mutex-timedlock.c b/sysdeps/mach/hurd/htl/pt-mutex-timedlock.c
index e83bc57875..3aa7d798b2 100644
--- a/sysdeps/mach/hurd/htl/pt-mutex-timedlock.c
+++ b/sysdeps/mach/hurd/htl/pt-mutex-timedlock.c
@@ -77,3 +77,4 @@ __pthread_mutex_timedlock (pthread_mutex_t *mtxp, const struct timespec *tsp)
   return ret;
 }
 strong_alias (__pthread_mutex_timedlock, pthread_mutex_timedlock)
+hidden_def (__pthread_mutex_timedlock)
diff --git a/sysdeps/mach/hurd/i386/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist
index 7c2cb2b05a..dd0d3c7317 100644
--- a/sysdeps/mach/hurd/i386/libc.abilist
+++ b/sysdeps/mach/hurd/i386/libc.abilist
@@ -2181,6 +2181,10 @@ GLIBC_2.3.4 setsourcefilter F
 GLIBC_2.3.4 xdr_quad_t F
 GLIBC_2.3.4 xdr_u_quad_t F
 GLIBC_2.30 twalk_r F
+GLIBC_2.32 thrd_current F
+GLIBC_2.32 thrd_equal F
+GLIBC_2.32 thrd_sleep F
+GLIBC_2.32 thrd_yield F
 GLIBC_2.4 __confstr_chk F
 GLIBC_2.4 __fgets_chk F
 GLIBC_2.4 __fgets_unlocked_chk F
diff --git a/sysdeps/mach/hurd/i386/libpthread.abilist b/sysdeps/mach/hurd/i386/libpthread.abilist
index cda8755960..0b90f9bf63 100644
--- a/sysdeps/mach/hurd/i386/libpthread.abilist
+++ b/sysdeps/mach/hurd/i386/libpthread.abilist
@@ -147,3 +147,24 @@ GLIBC_2.2.6 __errno_location F
 GLIBC_2.2.6 __h_errno_location F
 GLIBC_2.21 pthread_hurd_cond_timedwait_np F
 GLIBC_2.21 pthread_hurd_cond_wait_np F
+GLIBC_2.32 call_once F
+GLIBC_2.32 cnd_broadcast F
+GLIBC_2.32 cnd_destroy F
+GLIBC_2.32 cnd_init F
+GLIBC_2.32 cnd_signal F
+GLIBC_2.32 cnd_timedwait F
+GLIBC_2.32 cnd_wait F
+GLIBC_2.32 mtx_destroy F
+GLIBC_2.32 mtx_init F
+GLIBC_2.32 mtx_lock F
+GLIBC_2.32 mtx_timedlock F
+GLIBC_2.32 mtx_trylock F
+GLIBC_2.32 mtx_unlock F
+GLIBC_2.32 thrd_create F
+GLIBC_2.32 thrd_detach F
+GLIBC_2.32 thrd_exit F
+GLIBC_2.32 thrd_join F
+GLIBC_2.32 tss_create F
+GLIBC_2.32 tss_delete F
+GLIBC_2.32 tss_get F
+GLIBC_2.32 tss_set F
diff --git a/sysdeps/nptl/thrd_create.c b/sysdeps/nptl/thrd_create.c
new file mode 100644
index 0000000000..a9219db7bc
--- /dev/null
+++ b/sysdeps/nptl/thrd_create.c
@@ -0,0 +1,2 @@
+#define __pthread_create __pthread_create_2_1
+#include "../pthread/thrd_create.c"
diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile
index 7f9eadd0e2..889f10d8b1 100644
--- a/sysdeps/pthread/Makefile
+++ b/sysdeps/pthread/Makefile
@@ -25,3 +25,21 @@ $(objpfx)tst-timer: $(objpfx)librt.a $(static-thread-library)
 endif
 
 endif
+
+ifneq (,$(filter $(subdir),htl nptl))
+headers += threads.h
+
+routines += thrd_current thrd_equal thrd_sleep thrd_yield
+
+libpthread-routines += thrd_create thrd_detach thrd_exit thrd_join \
+       call_once \
+       mtx_destroy mtx_init mtx_lock mtx_timedlock \
+       mtx_trylock mtx_unlock \
+       cnd_broadcast \
+       cnd_destroy cnd_init cnd_signal cnd_timedwait cnd_wait \
+       tss_create tss_delete tss_get tss_set
+
+tests += tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \
+ tst-cnd-timedwait tst-thrd-detach tst-mtx-basic tst-thrd-sleep \
+ tst-mtx-recursive tst-tss-basic tst-call-once tst-mtx-timedlock
+endif
diff --git a/nptl/call_once.c b/sysdeps/pthread/call_once.c
similarity index 100%
rename from nptl/call_once.c
rename to sysdeps/pthread/call_once.c
diff --git a/nptl/cnd_broadcast.c b/sysdeps/pthread/cnd_broadcast.c
similarity index 100%
rename from nptl/cnd_broadcast.c
rename to sysdeps/pthread/cnd_broadcast.c
diff --git a/nptl/cnd_destroy.c b/sysdeps/pthread/cnd_destroy.c
similarity index 100%
rename from nptl/cnd_destroy.c
rename to sysdeps/pthread/cnd_destroy.c
diff --git a/nptl/cnd_init.c b/sysdeps/pthread/cnd_init.c
similarity index 100%
rename from nptl/cnd_init.c
rename to sysdeps/pthread/cnd_init.c
diff --git a/nptl/cnd_signal.c b/sysdeps/pthread/cnd_signal.c
similarity index 100%
rename from nptl/cnd_signal.c
rename to sysdeps/pthread/cnd_signal.c
diff --git a/nptl/cnd_timedwait.c b/sysdeps/pthread/cnd_timedwait.c
similarity index 100%
rename from nptl/cnd_timedwait.c
rename to sysdeps/pthread/cnd_timedwait.c
diff --git a/nptl/cnd_wait.c b/sysdeps/pthread/cnd_wait.c
similarity index 100%
rename from nptl/cnd_wait.c
rename to sysdeps/pthread/cnd_wait.c
diff --git a/nptl/mtx_destroy.c b/sysdeps/pthread/mtx_destroy.c
similarity index 100%
rename from nptl/mtx_destroy.c
rename to sysdeps/pthread/mtx_destroy.c
diff --git a/nptl/mtx_init.c b/sysdeps/pthread/mtx_init.c
similarity index 100%
rename from nptl/mtx_init.c
rename to sysdeps/pthread/mtx_init.c
diff --git a/nptl/mtx_lock.c b/sysdeps/pthread/mtx_lock.c
similarity index 100%
rename from nptl/mtx_lock.c
rename to sysdeps/pthread/mtx_lock.c
diff --git a/nptl/mtx_timedlock.c b/sysdeps/pthread/mtx_timedlock.c
similarity index 100%
rename from nptl/mtx_timedlock.c
rename to sysdeps/pthread/mtx_timedlock.c
diff --git a/nptl/mtx_trylock.c b/sysdeps/pthread/mtx_trylock.c
similarity index 100%
rename from nptl/mtx_trylock.c
rename to sysdeps/pthread/mtx_trylock.c
diff --git a/nptl/mtx_unlock.c b/sysdeps/pthread/mtx_unlock.c
similarity index 100%
rename from nptl/mtx_unlock.c
rename to sysdeps/pthread/mtx_unlock.c
diff --git a/nptl/thrd_create.c b/sysdeps/pthread/thrd_create.c
similarity index 91%
rename from nptl/thrd_create.c
rename to sysdeps/pthread/thrd_create.c
index fe08e22973..25af955419 100644
--- a/nptl/thrd_create.c
+++ b/sysdeps/pthread/thrd_create.c
@@ -24,7 +24,7 @@ thrd_create (thrd_t *thr, thrd_start_t func, void *arg)
   _Static_assert (sizeof (*thr) == sizeof (pthread_t),
   "sizeof (*thr) != sizeof (pthread_t)");
 
-  int err_code = __pthread_create_2_1 (thr, ATTR_C11_THREAD,
-       (void* (*) (void*))func, arg);
+  int err_code = __pthread_create (thr, ATTR_C11_THREAD,
+   (void* (*) (void*))func, arg);
   return thrd_err_map (err_code);
 }
diff --git a/nptl/thrd_detach.c b/sysdeps/pthread/thrd_detach.c
similarity index 100%
rename from nptl/thrd_detach.c
rename to sysdeps/pthread/thrd_detach.c
diff --git a/nptl/thrd_equal.c b/sysdeps/pthread/thrd_equal.c
similarity index 100%
rename from nptl/thrd_equal.c
rename to sysdeps/pthread/thrd_equal.c
diff --git a/nptl/thrd_exit.c b/sysdeps/pthread/thrd_exit.c
similarity index 100%
rename from nptl/thrd_exit.c
rename to sysdeps/pthread/thrd_exit.c
diff --git a/nptl/thrd_join.c b/sysdeps/pthread/thrd_join.c
similarity index 100%
rename from nptl/thrd_join.c
rename to sysdeps/pthread/thrd_join.c
diff --git a/nptl/thrd_priv.h b/sysdeps/pthread/thrd_priv.h
similarity index 100%
rename from nptl/thrd_priv.h
rename to sysdeps/pthread/thrd_priv.h
diff --git a/nptl/thrd_sleep.c b/sysdeps/pthread/thrd_sleep.c
similarity index 100%
rename from nptl/thrd_sleep.c
rename to sysdeps/pthread/thrd_sleep.c
diff --git a/sysdeps/nptl/threads.h b/sysdeps/pthread/threads.h
similarity index 100%
rename from sysdeps/nptl/threads.h
rename to sysdeps/pthread/threads.h
diff --git a/nptl/tss_create.c b/sysdeps/pthread/tss_create.c
similarity index 100%
rename from nptl/tss_create.c
rename to sysdeps/pthread/tss_create.c
diff --git a/nptl/tss_delete.c b/sysdeps/pthread/tss_delete.c
similarity index 100%
rename from nptl/tss_delete.c
rename to sysdeps/pthread/tss_delete.c
diff --git a/nptl/tss_get.c b/sysdeps/pthread/tss_get.c
similarity index 100%
rename from nptl/tss_get.c
rename to sysdeps/pthread/tss_get.c
diff --git a/nptl/tss_set.c b/sysdeps/pthread/tss_set.c
similarity index 100%
rename from nptl/tss_set.c
rename to sysdeps/pthread/tss_set.c
diff --git a/nptl/tst-call-once.c b/sysdeps/pthread/tst-call-once.c
similarity index 100%
rename from nptl/tst-call-once.c
rename to sysdeps/pthread/tst-call-once.c
diff --git a/nptl/tst-cnd-basic.c b/sysdeps/pthread/tst-cnd-basic.c
similarity index 100%
rename from nptl/tst-cnd-basic.c
rename to sysdeps/pthread/tst-cnd-basic.c
diff --git a/nptl/tst-cnd-broadcast.c b/sysdeps/pthread/tst-cnd-broadcast.c
similarity index 100%
rename from nptl/tst-cnd-broadcast.c
rename to sysdeps/pthread/tst-cnd-broadcast.c
diff --git a/nptl/tst-cnd-timedwait.c b/sysdeps/pthread/tst-cnd-timedwait.c
similarity index 100%
rename from nptl/tst-cnd-timedwait.c
rename to sysdeps/pthread/tst-cnd-timedwait.c
diff --git a/nptl/tst-mtx-basic.c b/sysdeps/pthread/tst-mtx-basic.c
similarity index 100%
rename from nptl/tst-mtx-basic.c
rename to sysdeps/pthread/tst-mtx-basic.c
diff --git a/nptl/tst-mtx-recursive.c b/sysdeps/pthread/tst-mtx-recursive.c
similarity index 100%
rename from nptl/tst-mtx-recursive.c
rename to sysdeps/pthread/tst-mtx-recursive.c
diff --git a/nptl/tst-mtx-timedlock.c b/sysdeps/pthread/tst-mtx-timedlock.c
similarity index 100%
rename from nptl/tst-mtx-timedlock.c
rename to sysdeps/pthread/tst-mtx-timedlock.c
diff --git a/nptl/tst-mtx-trylock.c b/sysdeps/pthread/tst-mtx-trylock.c
similarity index 100%
rename from nptl/tst-mtx-trylock.c
rename to sysdeps/pthread/tst-mtx-trylock.c
diff --git a/nptl/tst-thrd-detach.c b/sysdeps/pthread/tst-thrd-detach.c
similarity index 100%
rename from nptl/tst-thrd-detach.c
rename to sysdeps/pthread/tst-thrd-detach.c
diff --git a/nptl/tst-thrd-sleep.c b/sysdeps/pthread/tst-thrd-sleep.c
similarity index 100%
rename from nptl/tst-thrd-sleep.c
rename to sysdeps/pthread/tst-thrd-sleep.c
diff --git a/nptl/tst-tss-basic.c b/sysdeps/pthread/tst-tss-basic.c
similarity index 100%
rename from nptl/tst-tss-basic.c
rename to sysdeps/pthread/tst-tss-basic.c
--
2.24.1

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 01/10] htl: Rename _pthread_mutex_init/destroy to __pthread_mutex_init/destroy

Adhemerval Zanella-2
In reply to this post by Samuel Thibault


On 14/01/2020 15:52, Samuel Thibault wrote:

> ---
>  htl/Versions                              | 2 ++
>  htl/pt-initialize.c                       | 4 ++--
>  sysdeps/htl/pt-key.h                      | 2 +-
>  sysdeps/htl/pt-mutex-destroy.c            | 4 ++--
>  sysdeps/htl/pt-mutex-init.c               | 4 ++--
>  sysdeps/htl/pthreadP.h                    | 5 +++--
>  sysdeps/mach/hurd/htl/pt-mutex-destroy.c  | 4 ++--
>  sysdeps/mach/hurd/htl/pt-mutex-init.c     | 6 +++---
>  sysdeps/mach/hurd/i386/libpthread.abilist | 2 --
>  9 files changed, 17 insertions(+), 16 deletions(-)
>
> diff --git a/htl/Versions b/htl/Versions
> index 77f7335b9c..3ae4b5c17d 100644
> --- a/htl/Versions
> +++ b/htl/Versions
> @@ -155,6 +155,8 @@ libpthread {
>      __pthread_setspecific;
>      __pthread_getattr_np;
>      __pthread_attr_getstack;
> +    __pthread_mutex_init;
> +    __pthread_mutex_destroy;
>      __pthread_mutex_timedlock;
>    }
>  }
> diff --git a/htl/pt-initialize.c b/htl/pt-initialize.c
> index d5a64f7cd9..89ed742422 100644
> --- a/htl/pt-initialize.c
> +++ b/htl/pt-initialize.c
> @@ -51,8 +51,8 @@ static const struct pthread_functions pthread_functions = {
>    .ptr___pthread_exit = __pthread_exit,
>    .ptr_pthread_getschedparam = __pthread_getschedparam,
>    .ptr_pthread_setschedparam = __pthread_setschedparam,
> -  .ptr_pthread_mutex_destroy = _pthread_mutex_destroy,
> -  .ptr_pthread_mutex_init = _pthread_mutex_init,
> +  .ptr_pthread_mutex_destroy = __pthread_mutex_destroy,
> +  .ptr_pthread_mutex_init = __pthread_mutex_init,
>    .ptr_pthread_mutex_lock = __pthread_mutex_lock,
>    .ptr_pthread_mutex_trylock = __pthread_mutex_trylock,
>    .ptr_pthread_mutex_unlock = __pthread_mutex_unlock,
> diff --git a/sysdeps/htl/pt-key.h b/sysdeps/htl/pt-key.h
> index bfaa19900a..b547e8ad29 100644
> --- a/sysdeps/htl/pt-key.h
> +++ b/sysdeps/htl/pt-key.h
> @@ -66,7 +66,7 @@ __pthread_key_lock_ready (void)
>      err = __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
>      assert_perror (err);
>  
> -    err = _pthread_mutex_init (&__pthread_key_lock, &attr);
> +    err = __pthread_mutex_init (&__pthread_key_lock, &attr);
>      assert_perror (err);
>  
>      err = __pthread_mutexattr_destroy (&attr);
> diff --git a/sysdeps/htl/pt-mutex-destroy.c b/sysdeps/htl/pt-mutex-destroy.c
> index 3824e62dd4..796fc11b8d 100644
> --- a/sysdeps/htl/pt-mutex-destroy.c
> +++ b/sysdeps/htl/pt-mutex-destroy.c
> @@ -23,7 +23,7 @@
>  #include <pt-internal.h>
>  
>  int
> -_pthread_mutex_destroy (pthread_mutex_t *mutex)
> +__pthread_mutex_destroy (pthread_mutex_t *mutex)
>  {
>    if (mutex->__attr == __PTHREAD_ERRORCHECK_MUTEXATTR
>        || mutex->__attr == __PTHREAD_RECURSIVE_MUTEXATTR)
> @@ -35,4 +35,4 @@ _pthread_mutex_destroy (pthread_mutex_t *mutex)
>    return 0;
>  }
>  
> -strong_alias (_pthread_mutex_destroy, pthread_mutex_destroy);
> +strong_alias (__pthread_mutex_destroy, pthread_mutex_destroy);
> diff --git a/sysdeps/htl/pt-mutex-init.c b/sysdeps/htl/pt-mutex-init.c
> index c59bd8a3f5..77f041352e 100644
> --- a/sysdeps/htl/pt-mutex-init.c
> +++ b/sysdeps/htl/pt-mutex-init.c
> @@ -24,7 +24,7 @@
>  #include <pt-internal.h>
>  
>  int
> -_pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
> +__pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
>  {
>    *mutex = (pthread_mutex_t) __PTHREAD_MUTEX_INITIALIZER;
>  
> @@ -47,4 +47,4 @@ _pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
>    return 0;
>  }
>  
> -strong_alias (_pthread_mutex_init, pthread_mutex_init);
> +strong_alias (__pthread_mutex_init, pthread_mutex_init);

Why do we need both htl and Hurd implementation of pt-mutex-init.c
(same for pt-mutex-destroy)?

For Linux, some pthread implementation are at sysdeps folder
because either they issues syscalls directly (through
{INLINE,INTERNAL}_SYSCALL macros) or implement some arch-specific
facily (such as HLE or spinlocks).

> diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h
> index affe7cdf53..c6ddf76fd4 100644
> --- a/sysdeps/htl/pthreadP.h
> +++ b/sysdeps/htl/pthreadP.h
> @@ -27,7 +27,8 @@ extern pthread_t __pthread_self (void);
>  extern int __pthread_kill (pthread_t threadid, int signo);
>  extern struct __pthread **__pthread_threads;
>  
> -extern int _pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr);
> +extern int __pthread_mutex_init (pthread_mutex_t *__mutex, const pthread_mutexattr_t *__attr);
> +extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
>  extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
>  extern int __pthread_mutex_timedlock (pthread_mutex_t *__mutex,
>       const struct timespec *__abstime);
> @@ -73,7 +74,7 @@ struct __pthread_cancelation_handler **___pthread_get_cleanup_stack (void) attri
>  hidden_proto (__pthread_key_create)
>  hidden_proto (__pthread_getspecific)
>  hidden_proto (__pthread_setspecific)
> -hidden_proto (_pthread_mutex_init)
> +hidden_proto (__pthread_mutex_init)
>  #endif
>  
>  #define ASSERT_TYPE_SIZE(type, size) \
> diff --git a/sysdeps/mach/hurd/htl/pt-mutex-destroy.c b/sysdeps/mach/hurd/htl/pt-mutex-destroy.c
> index afab03234e..a8a0adc03f 100644
> --- a/sysdeps/mach/hurd/htl/pt-mutex-destroy.c
> +++ b/sysdeps/mach/hurd/htl/pt-mutex-destroy.c
> @@ -24,7 +24,7 @@
>  #include <hurdlock.h>
>  
>  int
> -_pthread_mutex_destroy (pthread_mutex_t *mtxp)
> +__pthread_mutex_destroy (pthread_mutex_t *mtxp)
>  {
>    atomic_read_barrier ();
>    if (*(volatile unsigned int *) &mtxp->__lock != 0)
> @@ -34,4 +34,4 @@ _pthread_mutex_destroy (pthread_mutex_t *mtxp)
>    return 0;
>  }
>  
> -strong_alias (_pthread_mutex_destroy, pthread_mutex_destroy)
> +strong_alias (__pthread_mutex_destroy, pthread_mutex_destroy)
> diff --git a/sysdeps/mach/hurd/htl/pt-mutex-init.c b/sysdeps/mach/hurd/htl/pt-mutex-init.c
> index 6b804116a5..7a2cc462f3 100644
> --- a/sysdeps/mach/hurd/htl/pt-mutex-init.c
> +++ b/sysdeps/mach/hurd/htl/pt-mutex-init.c
> @@ -32,7 +32,7 @@ static const pthread_mutexattr_t dfl_attr = {
>  };
>  
>  int
> -_pthread_mutex_init (pthread_mutex_t *mtxp, const pthread_mutexattr_t *attrp)
> +__pthread_mutex_init (pthread_mutex_t *mtxp, const pthread_mutexattr_t *attrp)
>  {
>    ASSERT_TYPE_SIZE (pthread_mutex_t, __SIZEOF_PTHREAD_MUTEX_T);
>  
> @@ -55,5 +55,5 @@ _pthread_mutex_init (pthread_mutex_t *mtxp, const pthread_mutexattr_t *attrp)
>    return 0;
>  }
>  
> -strong_alias (_pthread_mutex_init, pthread_mutex_init)
> -hidden_def (_pthread_mutex_init)
> +strong_alias (__pthread_mutex_init, pthread_mutex_init)
> +hidden_def (__pthread_mutex_init)
> diff --git a/sysdeps/mach/hurd/i386/libpthread.abilist b/sysdeps/mach/hurd/i386/libpthread.abilist
> index 0ede90859c..cda8755960 100644
> --- a/sysdeps/mach/hurd/i386/libpthread.abilist
> +++ b/sysdeps/mach/hurd/i386/libpthread.abilist
> @@ -14,8 +14,6 @@ GLIBC_2.12 _cthread_init_routine D 0x4
>  GLIBC_2.12 _cthreads_flockfile F
>  GLIBC_2.12 _cthreads_ftrylockfile F
>  GLIBC_2.12 _cthreads_funlockfile F
> -GLIBC_2.12 _pthread_mutex_destroy F
> -GLIBC_2.12 _pthread_mutex_init F
>  GLIBC_2.12 _pthread_mutex_lock F
>  GLIBC_2.12 _pthread_mutex_trylock F
>  GLIBC_2.12 _pthread_mutex_unlock F
>

I understand this change is follow Linux internal implementation
and make mtx_init.c generic, but I don't think changing hurd
libpthread exported symbols is the correct solution.

Since the symbol won't be used anymore I think we can move to
a compat symbol, something like:

+strong_alias (__pthread_mutex_init, pthread_mutex_init);
+hidden_def (__pthread_mutex_init)
+#if SHLIB_COMPAT (libpthread, GLIBC_2_12, GLIBC_2_31)
+compat_symbol (libpthread, __pthread_mutex_init, _pthread_mutex_init, GLIBC_2_12);
+#endif
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 02/10] htl: Add missing internal functions declarations

Adhemerval Zanella-2
In reply to this post by Samuel Thibault


On 14/01/2020 15:52, Samuel Thibault wrote:

> ---
>  sysdeps/htl/pthreadP.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/sysdeps/htl/pthreadP.h b/sysdeps/htl/pthreadP.h
> index c6ddf76fd4..b1c7575f89 100644
> --- a/sysdeps/htl/pthreadP.h
> +++ b/sysdeps/htl/pthreadP.h
> @@ -30,11 +30,22 @@ extern struct __pthread **__pthread_threads;
>  extern int __pthread_mutex_init (pthread_mutex_t *__mutex, const pthread_mutexattr_t *__attr);
>  extern int __pthread_mutex_destroy (pthread_mutex_t *__mutex);
>  extern int __pthread_mutex_lock (pthread_mutex_t *__mutex);
> +extern int __pthread_mutex_trylock (pthread_mutex_t *_mutex);
>  extern int __pthread_mutex_timedlock (pthread_mutex_t *__mutex,
>       const struct timespec *__abstime);
>  extern int __pthread_mutex_unlock (pthread_mutex_t *__mutex);
> +extern int __pthread_mutexattr_init (pthread_mutexattr_t *attr);
> +extern int __pthread_mutexattr_settype (pthread_mutexattr_t *attr, int kind);
>  
> +extern int __pthread_cond_init (pthread_cond_t *cond,
> + const pthread_condattr_t *cond_attr);
> +extern int __pthread_cond_signal (pthread_cond_t *cond);
>  extern int __pthread_cond_broadcast (pthread_cond_t *cond);
> +extern int __pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex);
> +extern int __pthread_cond_timedwait (pthread_cond_t *cond,
> +     pthread_mutex_t *mutex,
> +     const struct timespec *abstime);
> +extern int __pthread_cond_destroy (pthread_cond_t *cond);
>  
>  typedef struct __cthread *__cthread_t;
>  typedef int __cthread_key_t;
> @@ -55,6 +66,8 @@ int __cthread_setspecific (__cthread_key_t, void *);
>  int __pthread_key_create (pthread_key_t *key, void (*destr) (void *));
>  void *__pthread_getspecific (pthread_key_t key);
>  int __pthread_setspecific (pthread_key_t key, const void *value);
> +int __pthread_key_delete (pthread_key_t key);
> +int __pthread_once (pthread_once_t *once_control, void (*init_routine) (void));
>  
>  int __pthread_setcancelstate (int state, int *oldstate);

LGTM, although I can't really tests.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 03/10] htl: Add support for C11 threads behavior

Adhemerval Zanella-2
In reply to this post by Samuel Thibault


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 <[hidden email]>

> ---
>  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.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 04/10] htl: Make __PTHREAD_ONCE_INIT more flexible

Adhemerval Zanella-2
In reply to this post by Samuel Thibault


On 14/01/2020 15:52, Samuel Thibault wrote:
> by moving its (struct __pthread_once) cast into PTHREAD_ONCE_INIT.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <[hidden email]>

> ---
>  sysdeps/htl/bits/types/struct___pthread_once.h | 2 +-
>  sysdeps/htl/pthread.h                          | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/sysdeps/htl/bits/types/struct___pthread_once.h b/sysdeps/htl/bits/types/struct___pthread_once.h
> index 31a0c0817b..a6b6db708c 100644
> --- a/sysdeps/htl/bits/types/struct___pthread_once.h
> +++ b/sysdeps/htl/bits/types/struct___pthread_once.h
> @@ -28,6 +28,6 @@ struct __pthread_once
>  };
>  
>  #define __PTHREAD_ONCE_INIT \
> - (struct __pthread_once) { 0, __PTHREAD_SPIN_LOCK_INITIALIZER }
> + 0, __PTHREAD_SPIN_LOCK_INITIALIZER
>  
>  #endif /* bits/types/struct___pthread_once.h */

Ok.

> diff --git a/sysdeps/htl/pthread.h b/sysdeps/htl/pthread.h
> index 3216860493..38c61e8da3 100644
> --- a/sysdeps/htl/pthread.h
> +++ b/sysdeps/htl/pthread.h
> @@ -802,7 +802,7 @@ extern int pthread_setspecific (pthread_key_t __key, const void *__value)
>  
>  #include <bits/types/struct___pthread_once.h>
>  
> -#define PTHREAD_ONCE_INIT __PTHREAD_ONCE_INIT
> +#define PTHREAD_ONCE_INIT (struct __pthread_once) { __PTHREAD_ONCE_INIT }
>  
>  /* Call INIT_ROUTINE if this function has never been called with
>     *ONCE_CONTROL, otherwise do nothing.  */
>

Ok, although I think the cast is superfluous.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 04/10] htl: Make __PTHREAD_ONCE_INIT more flexible

Samuel Thibault
Adhemerval Zanella, le lun. 20 janv. 2020 15:01:13 -0300, a ecrit:
> > - (struct __pthread_once) { 0, __PTHREAD_SPIN_LOCK_INITIALIZER }
> > + 0, __PTHREAD_SPIN_LOCK_INITIALIZER

> > -#define PTHREAD_ONCE_INIT __PTHREAD_ONCE_INIT
> > +#define PTHREAD_ONCE_INIT (struct __pthread_once) { __PTHREAD_ONCE_INIT }
>
> Ok, although I think the cast is superfluous.

I think so as well, but preferred to keep it for now, so that this
series is a no-op in that regard :)

Samuel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 05/10] nptl: Move nptl-specific types to separate header

Adhemerval Zanella-2
In reply to this post by Samuel Thibault
LGTM, thanks.

Reviewed-by: Adhemerval Zanella <[hidden email]>

On 14/01/2020 15:52, Samuel Thibault wrote:

> ---
>  nptl/call_once.c                        |  2 +-
>  sysdeps/nptl/bits/thread-shared-types.h | 10 ++++++++++
>  sysdeps/nptl/threads.h                  | 13 +++++--------
>  3 files changed, 16 insertions(+), 9 deletions(-)
>
> diff --git a/nptl/call_once.c b/nptl/call_once.c
> index 3f880a9073..25e2964c76 100644
> --- a/nptl/call_once.c
> +++ b/nptl/call_once.c
> @@ -27,5 +27,5 @@ call_once (once_flag *flag, void (*func)(void))
>    "sizeof (once_flag) != sizeof (pthread_once_t)");
>    _Static_assert (alignof (once_flag) == alignof (pthread_once_t),
>    "alignof (once_flag) != alignof (pthread_once_t)");
> -  __pthread_once (&flag->__data, func);
> +  __pthread_once ((pthread_once_t *) flag, func);
>  }

Ok.

> diff --git a/sysdeps/nptl/bits/thread-shared-types.h b/sysdeps/nptl/bits/thread-shared-types.h
> index fd08b6916a..fbbdd0bb36 100644
> --- a/sysdeps/nptl/bits/thread-shared-types.h
> +++ b/sysdeps/nptl/bits/thread-shared-types.h
> @@ -116,4 +116,14 @@ struct __pthread_cond_s
>    unsigned int __g_signals[2];
>  };
>  
> +typedef unsigned int __tss_t;
> +typedef unsigned long int __thrd_t;
> +
> +typedef struct
> +{
> +  int __data __ONCE_ALIGNMENT;
> +} __once_flag;
> +
> +#define __ONCE_FLAG_INIT { 0 }
> +
>  #endif /* _THREAD_SHARED_TYPES_H  */

Ok.

> diff --git a/sysdeps/nptl/threads.h b/sysdeps/nptl/threads.h
> index 6d5e4bfe02..0ac489b4a1 100644
> --- a/sysdeps/nptl/threads.h
> +++ b/sysdeps/nptl/threads.h
> @@ -24,7 +24,7 @@
>  
>  __BEGIN_DECLS
>  
> -#include <bits/pthreadtypes-arch.h>
> +#include <bits/thread-shared-types.h>
>  #include <bits/types/struct_timespec.h>
>  
>  #ifndef __cplusplus

Ok, thread-shared-types.h includes pthreadtypes-arch.h.

> @@ -32,10 +32,10 @@ __BEGIN_DECLS
>  #endif
>  
>  #define TSS_DTOR_ITERATIONS 4
> -typedef unsigned int tss_t;
> +typedef __tss_t tss_t;
>  typedef void (*tss_dtor_t) (void*);
>  
> -typedef unsigned long int thrd_t;
> +typedef __thrd_t thrd_t;
>  typedef int (*thrd_start_t) (void*);
>  
>  /* Exit and error codes.  */
> @@ -56,11 +56,8 @@ enum
>    mtx_timed     = 2
>  };
>  
> -typedef struct
> -{
> -  int __data __ONCE_ALIGNMENT;
> -} once_flag;
> -#define ONCE_FLAG_INIT { 0 }
> +typedef __once_flag once_flag;
> +#define ONCE_FLAG_INIT __ONCE_FLAG_INIT
>  
>  typedef union
>  {
>

Ok.
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 06/10] C11 threads: do not require PTHREAD_DESTRUCTOR_ITERATIONS

Adhemerval Zanella-2
In reply to this post by Samuel Thibault


On 14/01/2020 15:52, Samuel Thibault wrote:
> It is optional in POSIX.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <[hidden email]>

> ---
>  nptl/tss_create.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/nptl/tss_create.c b/nptl/tss_create.c
> index ea1f2e0fba..4e170dd4fc 100644
> --- a/nptl/tss_create.c
> +++ b/nptl/tss_create.c
> @@ -23,8 +23,10 @@ tss_create (tss_t *tss_id, tss_dtor_t destructor)
>  {
>    _Static_assert (sizeof (tss_t) == sizeof (pthread_key_t),
>    "sizeof (tss_t) != sizeof (pthread_key_t)");
> +#ifdef PTHREAD_DESTRUCTOR_ITERATIONS
>    _Static_assert (TSS_DTOR_ITERATIONS == PTHREAD_DESTRUCTOR_ITERATIONS,
>    "TSS_DTOR_ITERATIONS != PTHREAD_DESTRUCTOR_ITERATIONS");
> +#endif
>  
>    int err_code = __pthread_key_create (tss_id, destructor);
>    return thrd_err_map (err_code);
>
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 07/10] C11 threads: Fix thrd_t / pthread_t compatibility assertion

Adhemerval Zanella-2
In reply to this post by Samuel Thibault
LGTM with a small nit below.

Reviewed-by: Adhemerval Zanella <[hidden email]>

On 14/01/2020 15:52, Samuel Thibault wrote:

> ---
>  nptl/thrd_create.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/nptl/thrd_create.c b/nptl/thrd_create.c
> index 8474e234c9..fe08e22973 100644
> --- a/nptl/thrd_create.c
> +++ b/nptl/thrd_create.c
> @@ -21,8 +21,8 @@
>  int
>  thrd_create (thrd_t *thr, thrd_start_t func, void *arg)
>  {
> -  _Static_assert (sizeof (thr) == sizeof (pthread_t),
> -  "sizeof (thr) != sizeof (pthread_t)");
> +  _Static_assert (sizeof (*thr) == sizeof (pthread_t),
> +  "sizeof (*thr) != sizeof (pthread_t)");
>  
>    int err_code = __pthread_create_2_1 (thr, ATTR_C11_THREAD,
>         (void* (*) (void*))func, arg);
>

I think it is better to use the type direct as other C11 implementation,
_Static_assert (sizeof (thrd_t) == sizeof (pthread_t), ...).
12