aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/pthread
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2020-01-13 19:58:28 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2020-02-09 13:56:48 +0100
commitb05de1040009d0d07a5a2e2765cffe554ffbe6ac (patch)
tree2b112a97ce7947699fac8b6df47e6db0b5196ded /sysdeps/pthread
parent6cefe985b869e7b33b05ce7252410474d8a6c3ad (diff)
downloadglibc-b05de1040009d0d07a5a2e2765cffe554ffbe6ac.tar.xz
glibc-b05de1040009d0d07a5a2e2765cffe554ffbe6ac.zip
C11 threads: Move implementation to sysdeps/pthread
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>
Diffstat (limited to 'sysdeps/pthread')
-rw-r--r--sysdeps/pthread/Makefile18
-rw-r--r--sysdeps/pthread/call_once.c31
-rw-r--r--sysdeps/pthread/cnd_broadcast.c26
-rw-r--r--sysdeps/pthread/cnd_destroy.c26
-rw-r--r--sysdeps/pthread/cnd_init.c33
-rw-r--r--sysdeps/pthread/cnd_signal.c26
-rw-r--r--sysdeps/pthread/cnd_timedwait.c29
-rw-r--r--sysdeps/pthread/cnd_wait.c27
-rw-r--r--sysdeps/pthread/mtx_destroy.c26
-rw-r--r--sysdeps/pthread/mtx_init.c53
-rw-r--r--sysdeps/pthread/mtx_lock.c26
-rw-r--r--sysdeps/pthread/mtx_timedlock.c28
-rw-r--r--sysdeps/pthread/mtx_trylock.c26
-rw-r--r--sysdeps/pthread/mtx_unlock.c26
-rw-r--r--sysdeps/pthread/thrd_create.c30
-rw-r--r--sysdeps/pthread/thrd_detach.c28
-rw-r--r--sysdeps/pthread/thrd_equal.c25
-rw-r--r--sysdeps/pthread/thrd_exit.c25
-rw-r--r--sysdeps/pthread/thrd_join.c30
-rw-r--r--sysdeps/pthread/thrd_priv.h45
-rw-r--r--sysdeps/pthread/thrd_sleep.c36
-rw-r--r--sysdeps/pthread/threads.h204
-rw-r--r--sysdeps/pthread/tss_create.c33
-rw-r--r--sysdeps/pthread/tss_delete.c25
-rw-r--r--sysdeps/pthread/tss_get.c25
-rw-r--r--sysdeps/pthread/tss_set.c26
-rw-r--r--sysdeps/pthread/tst-call-once.c66
-rw-r--r--sysdeps/pthread/tst-cnd-basic.c80
-rw-r--r--sysdeps/pthread/tst-cnd-broadcast.c97
-rw-r--r--sysdeps/pthread/tst-cnd-timedwait.c84
-rw-r--r--sysdeps/pthread/tst-mtx-basic.c73
-rw-r--r--sysdeps/pthread/tst-mtx-recursive.c45
-rw-r--r--sysdeps/pthread/tst-mtx-timedlock.c103
-rw-r--r--sysdeps/pthread/tst-mtx-trylock.c90
-rw-r--r--sysdeps/pthread/tst-thrd-detach.c52
-rw-r--r--sysdeps/pthread/tst-thrd-sleep.c51
-rw-r--r--sysdeps/pthread/tst-tss-basic.c75
37 files changed, 1749 insertions, 0 deletions
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/sysdeps/pthread/call_once.c b/sysdeps/pthread/call_once.c
new file mode 100644
index 0000000000..25e2964c76
--- /dev/null
+++ b/sysdeps/pthread/call_once.c
@@ -0,0 +1,31 @@
+/* C11 threads call once 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 <stdalign.h>
+
+#include "thrd_priv.h"
+
+void
+call_once (once_flag *flag, void (*func)(void))
+{
+ _Static_assert (sizeof (once_flag) == sizeof (pthread_once_t),
+ "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 ((pthread_once_t *) flag, func);
+}
diff --git a/sysdeps/pthread/cnd_broadcast.c b/sysdeps/pthread/cnd_broadcast.c
new file mode 100644
index 0000000000..66e0fce0c6
--- /dev/null
+++ b/sysdeps/pthread/cnd_broadcast.c
@@ -0,0 +1,26 @@
+/* C11 thread conditional broadcast 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"
+
+int
+cnd_broadcast (cnd_t *cond)
+{
+ int err_code = __pthread_cond_broadcast ((pthread_cond_t*) cond);
+ return thrd_err_map (err_code);
+}
diff --git a/sysdeps/pthread/cnd_destroy.c b/sysdeps/pthread/cnd_destroy.c
new file mode 100644
index 0000000000..763e91cb0f
--- /dev/null
+++ b/sysdeps/pthread/cnd_destroy.c
@@ -0,0 +1,26 @@
+/* C11 threads conditional destroy 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"
+#include "pthreadP.h"
+
+void
+cnd_destroy (cnd_t *cond)
+{
+ __pthread_cond_destroy ((pthread_cond_t *) cond);
+}
diff --git a/sysdeps/pthread/cnd_init.c b/sysdeps/pthread/cnd_init.c
new file mode 100644
index 0000000000..e8d7d68a2c
--- /dev/null
+++ b/sysdeps/pthread/cnd_init.c
@@ -0,0 +1,33 @@
+/* C11 thread conditional initialization 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 <stdalign.h>
+
+#include "thrd_priv.h"
+
+int
+cnd_init (cnd_t *cond)
+{
+ _Static_assert (sizeof (cnd_t) == sizeof (pthread_cond_t),
+ "(sizeof (cnd_t) != sizeof (pthread_cond_t)");
+ _Static_assert (alignof (cnd_t) == alignof (pthread_cond_t),
+ "alignof (cnd_t) != alignof (pthread_cond_t)");
+
+ int err_code = __pthread_cond_init ((pthread_cond_t *)cond, NULL);
+ return thrd_err_map (err_code);
+}
diff --git a/sysdeps/pthread/cnd_signal.c b/sysdeps/pthread/cnd_signal.c
new file mode 100644
index 0000000000..27155ffc1b
--- /dev/null
+++ b/sysdeps/pthread/cnd_signal.c
@@ -0,0 +1,26 @@
+/* C11 threads conditional signal 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"
+
+int
+cnd_signal (cnd_t *cond)
+{
+ int err_code = __pthread_cond_signal ((pthread_cond_t *) cond);
+ return thrd_err_map (err_code);
+}
diff --git a/sysdeps/pthread/cnd_timedwait.c b/sysdeps/pthread/cnd_timedwait.c
new file mode 100644
index 0000000000..c7f5309cf7
--- /dev/null
+++ b/sysdeps/pthread/cnd_timedwait.c
@@ -0,0 +1,29 @@
+/* C11 threads conditional timed wait 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"
+
+int
+cnd_timedwait (cnd_t *restrict cond, mtx_t *restrict mutex,
+ const struct timespec* restrict time_point)
+{
+ int err_code = __pthread_cond_timedwait ((pthread_cond_t *) cond,
+ (pthread_mutex_t *) mutex,
+ time_point);
+ return thrd_err_map (err_code);
+}
diff --git a/sysdeps/pthread/cnd_wait.c b/sysdeps/pthread/cnd_wait.c
new file mode 100644
index 0000000000..8070ca7c6a
--- /dev/null
+++ b/sysdeps/pthread/cnd_wait.c
@@ -0,0 +1,27 @@
+/* C11 threads conditional wait implementaiton.
+ 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"
+
+int
+cnd_wait (cnd_t *cond, mtx_t *mutex)
+{
+ int err_code = __pthread_cond_wait ((pthread_cond_t *) cond,
+ (pthread_mutex_t *) mutex);
+ return thrd_err_map (err_code);
+}
diff --git a/sysdeps/pthread/mtx_destroy.c b/sysdeps/pthread/mtx_destroy.c
new file mode 100644
index 0000000000..9ac324c8f8
--- /dev/null
+++ b/sysdeps/pthread/mtx_destroy.c
@@ -0,0 +1,26 @@
+/* C11 threads mutex destroy 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"
+#include "pthreadP.h"
+
+void
+mtx_destroy (mtx_t *mutex)
+{
+ __pthread_mutex_destroy ((pthread_mutex_t *) mutex);
+}
diff --git a/sysdeps/pthread/mtx_init.c b/sysdeps/pthread/mtx_init.c
new file mode 100644
index 0000000000..436a03673e
--- /dev/null
+++ b/sysdeps/pthread/mtx_init.c
@@ -0,0 +1,53 @@
+/* C11 threads mutex initialization 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 <stdalign.h>
+
+#include "thrd_priv.h"
+
+int
+mtx_init (mtx_t *mutex, int type)
+{
+ _Static_assert (sizeof (mtx_t) == sizeof (pthread_mutex_t),
+ "sizeof (mtx_t) != sizeof (pthread_mutex_t)");
+ _Static_assert (alignof (mtx_t) == alignof (pthread_mutex_t),
+ "alignof (mtx_t) != alignof (pthread_mutex_t)");
+
+ pthread_mutexattr_t attr;
+
+ __pthread_mutexattr_init (&attr);
+
+ /* Another possible solution would be to set the flags directly in
+ mutex object. */
+ switch (type)
+ {
+ case mtx_plain | mtx_recursive:
+ case mtx_timed | mtx_recursive:
+ __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
+ break;
+ case mtx_plain:
+ case mtx_timed: /* No difference between both in standard */
+ default:
+ __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_NORMAL);
+ break;
+ }
+
+ int err_code = __pthread_mutex_init ((pthread_mutex_t *) mutex, &attr);
+ /* pthread_mutexattr_destroy implementation is a noop. */
+ return thrd_err_map (err_code);
+}
diff --git a/sysdeps/pthread/mtx_lock.c b/sysdeps/pthread/mtx_lock.c
new file mode 100644
index 0000000000..cf1632b3f2
--- /dev/null
+++ b/sysdeps/pthread/mtx_lock.c
@@ -0,0 +1,26 @@
+/* C11 threads mutex lock 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"
+
+int
+mtx_lock (mtx_t *mutex)
+{
+ int err_code = __pthread_mutex_lock ((pthread_mutex