]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
C11 threads: Move implementation to sysdeps/pthread
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Mon, 13 Jan 2020 19:58:28 +0000 (19:58 +0000)
committerSamuel Thibault <samuel.thibault@ens-lyon.org>
Sun, 9 Feb 2020 12:56:48 +0000 (13:56 +0100)
so it gets shared by nptl and htl. Also add htl versions of thrd_current and
thrd_yield.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
49 files changed:
htl/Versions
nptl/Makefile
sysdeps/htl/pthreadP.h
sysdeps/htl/thrd_current.c [new file with mode: 0644]
sysdeps/htl/threads.h [deleted file]
sysdeps/hurd/stdc-predef.h [deleted file]
sysdeps/mach/htl/thrd_yield.c [new file with mode: 0644]
sysdeps/mach/hurd/htl/pt-mutex-destroy.c
sysdeps/mach/hurd/htl/pt-mutex-timedlock.c
sysdeps/mach/hurd/i386/libc.abilist
sysdeps/mach/hurd/i386/libpthread.abilist
sysdeps/nptl/thrd_create.c [new file with mode: 0644]
sysdeps/pthread/Makefile
sysdeps/pthread/call_once.c [moved from nptl/call_once.c with 100% similarity]
sysdeps/pthread/cnd_broadcast.c [moved from nptl/cnd_broadcast.c with 100% similarity]
sysdeps/pthread/cnd_destroy.c [moved from nptl/cnd_destroy.c with 100% similarity]
sysdeps/pthread/cnd_init.c [moved from nptl/cnd_init.c with 100% similarity]
sysdeps/pthread/cnd_signal.c [moved from nptl/cnd_signal.c with 100% similarity]
sysdeps/pthread/cnd_timedwait.c [moved from nptl/cnd_timedwait.c with 100% similarity]
sysdeps/pthread/cnd_wait.c [moved from nptl/cnd_wait.c with 100% similarity]
sysdeps/pthread/mtx_destroy.c [moved from nptl/mtx_destroy.c with 100% similarity]
sysdeps/pthread/mtx_init.c [moved from nptl/mtx_init.c with 100% similarity]
sysdeps/pthread/mtx_lock.c [moved from nptl/mtx_lock.c with 100% similarity]
sysdeps/pthread/mtx_timedlock.c [moved from nptl/mtx_timedlock.c with 100% similarity]
sysdeps/pthread/mtx_trylock.c [moved from nptl/mtx_trylock.c with 100% similarity]
sysdeps/pthread/mtx_unlock.c [moved from nptl/mtx_unlock.c with 100% similarity]
sysdeps/pthread/thrd_create.c [moved from nptl/thrd_create.c with 91% similarity]
sysdeps/pthread/thrd_detach.c [moved from nptl/thrd_detach.c with 100% similarity]
sysdeps/pthread/thrd_equal.c [moved from nptl/thrd_equal.c with 100% similarity]
sysdeps/pthread/thrd_exit.c [moved from nptl/thrd_exit.c with 100% similarity]
sysdeps/pthread/thrd_join.c [moved from nptl/thrd_join.c with 100% similarity]
sysdeps/pthread/thrd_priv.h [moved from nptl/thrd_priv.h with 100% similarity]
sysdeps/pthread/thrd_sleep.c [moved from nptl/thrd_sleep.c with 100% similarity]
sysdeps/pthread/threads.h [moved from sysdeps/nptl/threads.h with 100% similarity]
sysdeps/pthread/tss_create.c [moved from nptl/tss_create.c with 100% similarity]
sysdeps/pthread/tss_delete.c [moved from nptl/tss_delete.c with 100% similarity]
sysdeps/pthread/tss_get.c [moved from nptl/tss_get.c with 100% similarity]
sysdeps/pthread/tss_set.c [moved from nptl/tss_set.c with 100% similarity]
sysdeps/pthread/tst-call-once.c [moved from nptl/tst-call-once.c with 100% similarity]
sysdeps/pthread/tst-cnd-basic.c [moved from nptl/tst-cnd-basic.c with 100% similarity]
sysdeps/pthread/tst-cnd-broadcast.c [moved from nptl/tst-cnd-broadcast.c with 100% similarity]
sysdeps/pthread/tst-cnd-timedwait.c [moved from nptl/tst-cnd-timedwait.c with 100% similarity]
sysdeps/pthread/tst-mtx-basic.c [moved from nptl/tst-mtx-basic.c with 100% similarity]
sysdeps/pthread/tst-mtx-recursive.c [moved from nptl/tst-mtx-recursive.c with 100% similarity]
sysdeps/pthread/tst-mtx-timedlock.c [moved from nptl/tst-mtx-timedlock.c with 100% similarity]
sysdeps/pthread/tst-mtx-trylock.c [moved from nptl/tst-mtx-trylock.c with 100% similarity]
sysdeps/pthread/tst-thrd-detach.c [moved from nptl/tst-thrd-detach.c with 100% similarity]
sysdeps/pthread/tst-thrd-sleep.c [moved from nptl/tst-thrd-sleep.c with 100% similarity]
sysdeps/pthread/tst-tss-basic.c [moved from nptl/tst-tss-basic.c with 100% similarity]

index f9281649a7b361a66a0a7092098591a2306778d5..4f5f727753d7b92ba76769197af6c89822b22ca0 100644 (file)
@@ -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;
@@ -136,6 +142,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;
index ae530a5bae4869c823d7167c751d5196235d1e1f..f762ea26a376dae9fc503300ec8a3091a4c40085 100644 (file)
@@ -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
index fc8c9bc59150a79bf28171f3124e37b44a9543e4..fd1e697e39bd332292dc7597a46a214a23f4c935 100644 (file)
@@ -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 (file)
index 0000000..6304cd7
--- /dev/null
@@ -0,0 +1,31 @@
+/* C11 threads current thread implementation.
+   Copyright (C) 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 (file)
index 3c04fbc..0000000
+++ /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 (file)
index a7bb5f7..0000000
+++ /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 (file)
index 0000000..48e17e1
--- /dev/null
@@ -0,0 +1,26 @@
+/* sched_yield -- yield the processor.  Mach version.
+   Copyright (C) 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 ();
+}
index a8a0adc03fd772e272ab0bca28e4df65add15881..a5bfaddcb211aa67ee7bd3e3cdf630984faedd16 100644 (file)
@@ -35,3 +35,4 @@ __pthread_mutex_destroy (pthread_mutex_t *mtxp)
 }
 
 strong_alias (__pthread_mutex_destroy, pthread_mutex_destroy)
+hidden_def (__pthread_mutex_destroy)
index e83bc5787565a1cd91405120d9d87326d237f3b1..3aa7d798b23310d83e52961ea4ac39239e98c9d2 100644 (file)
@@ -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)
index 7c2cb2b05a788695b12f430b606d9440ed304bbc..dd0d3c7317e6d219c1767336acc9ea65395dd613 100644 (file)
@@ -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
index 14ef22e3dba96280367d14bee1305ce0f2d1d473..4a5e1fb7508e9280ab710276458b612a0b7f9b69 100644 (file)
@@ -142,3 +142,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 (file)
index 0000000..596a7ba
--- /dev/null
@@ -0,0 +1,2 @@
+#define __pthread_create __pthread_create_2_1
+#include <sysdeps/pthread/thrd_create.c>
index 7f9eadd0e29e61f05cda36be0b08f5eef18d18da..889f10d8b1f6f22a0784b0a9c73833113e50dc4c 100644 (file)
@@ -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
similarity index 100%
rename from nptl/call_once.c
rename to sysdeps/pthread/call_once.c
similarity index 100%
rename from nptl/cnd_init.c
rename to sysdeps/pthread/cnd_init.c
similarity index 100%
rename from nptl/cnd_wait.c
rename to sysdeps/pthread/cnd_wait.c
similarity index 100%
rename from nptl/mtx_init.c
rename to sysdeps/pthread/mtx_init.c
similarity index 100%
rename from nptl/mtx_lock.c
rename to sysdeps/pthread/mtx_lock.c
similarity index 91%
rename from nptl/thrd_create.c
rename to sysdeps/pthread/thrd_create.c
index 8423ffc80593b75a147988c4575a45e1d9ddc64c..4c47f053af57279c8203f62b9d698b9a485249bc 100644 (file)
@@ -24,7 +24,7 @@ thrd_create (thrd_t *thr, thrd_start_t func, void *arg)
   _Static_assert (sizeof (thrd_t) == sizeof (pthread_t),
                  "sizeof (thrd_t) != 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);
 }
similarity index 100%
rename from nptl/thrd_exit.c
rename to sysdeps/pthread/thrd_exit.c
similarity index 100%
rename from nptl/thrd_join.c
rename to sysdeps/pthread/thrd_join.c
similarity index 100%
rename from nptl/thrd_priv.h
rename to sysdeps/pthread/thrd_priv.h
similarity index 100%
rename from nptl/tss_get.c
rename to sysdeps/pthread/tss_get.c
similarity index 100%
rename from nptl/tss_set.c
rename to sysdeps/pthread/tss_set.c