aboutsummaryrefslogtreecommitdiff
path: root/nptl
diff options
context:
space:
mode:
Diffstat (limited to 'nptl')
-rw-r--r--nptl/Makefile3
-rw-r--r--nptl/Versions3
-rw-r--r--nptl/cnd_broadcast.c26
-rw-r--r--nptl/cnd_destroy.c26
-rw-r--r--nptl/cnd_init.c33
-rw-r--r--nptl/cnd_signal.c26
-rw-r--r--nptl/cnd_timedwait.c29
-rw-r--r--nptl/cnd_wait.c27
-rw-r--r--nptl/threads.h34
9 files changed, 205 insertions, 2 deletions
diff --git a/nptl/Makefile b/nptl/Makefile
index d55d24b09a..0864aee581 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -143,7 +143,8 @@ libpthread-routines = nptl-init nptlfreeres vars events version pt-interp \
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
+ mtx_trylock mtx_unlock call_once cnd_broadcast \
+ cnd_destroy cnd_init cnd_signal cnd_timedwait cnd_wait
# pthread_setuid pthread_seteuid pthread_setreuid \
# pthread_setresuid \
# pthread_setgid pthread_setegid pthread_setregid \
diff --git a/nptl/Versions b/nptl/Versions
index 0fdba18c74..9c38d67e72 100644
--- a/nptl/Versions
+++ b/nptl/Versions
@@ -273,7 +273,8 @@ libpthread {
GLIBC_2.28 {
thrd_create; thrd_detach; thrd_exit; thrd_join;
mtx_init; mtx_lock; mtx_timedlock; mtx_trylock; mtx_unlock; mtx_destroy;
- call_once;
+ call_once; cnd_broadcast; cnd_destroy; cnd_init; cnd_signal;
+ cnd_timedwait; cnd_wait;
}
GLIBC_PRIVATE {
diff --git a/nptl/cnd_broadcast.c b/nptl/cnd_broadcast.c
new file mode 100644
index 0000000000..889f88e2ed
--- /dev/null
+++ b/nptl/cnd_broadcast.c
@@ -0,0 +1,26 @@
+/* C11 thread conditional broadcast implementation.
+ Copyright (C) 2018 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
+ <http://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/nptl/cnd_destroy.c b/nptl/cnd_destroy.c
new file mode 100644
index 0000000000..37df9e9a2d
--- /dev/null
+++ b/nptl/cnd_destroy.c
@@ -0,0 +1,26 @@
+/* C11 threads conditional destroy implementation.
+ Copyright (C) 2018 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
+ <http://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/nptl/cnd_init.c b/nptl/cnd_init.c
new file mode 100644
index 0000000000..13f0f80a08
--- /dev/null
+++ b/nptl/cnd_init.c
@@ -0,0 +1,33 @@
+/* C11 thread conditional initialization implementation.
+ Copyright (C) 2018 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
+ <http://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/nptl/cnd_signal.c b/nptl/cnd_signal.c
new file mode 100644
index 0000000000..8ae650ba38
--- /dev/null
+++ b/nptl/cnd_signal.c
@@ -0,0 +1,26 @@
+/* C11 threads conditional signal implementation.
+ Copyright (C) 2018 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
+ <http://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/nptl/cnd_timedwait.c b/nptl/cnd_timedwait.c
new file mode 100644
index 0000000000..75358fef44
--- /dev/null
+++ b/nptl/cnd_timedwait.c
@@ -0,0 +1,29 @@
+/* C11 threads conditional timed wait implementation.
+ Copyright (C) 2018 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
+ <http://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/nptl/cnd_wait.c b/nptl/cnd_wait.c
new file mode 100644
index 0000000000..727d9bb697
--- /dev/null
+++ b/nptl/cnd_wait.c
@@ -0,0 +1,27 @@
+/* C11 threads conditional wait implementaiton.
+ Copyright (C) 2018 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
+ <http://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/nptl/threads.h b/nptl/threads.h
index 32f7cf8f75..e46b1b7f32 100644
--- a/nptl/threads.h
+++ b/nptl/threads.h
@@ -60,6 +60,12 @@ typedef union
long int __align __LOCK_ALIGNMENT;
} mtx_t;
+typedef union
+{
+ char __size[__SIZEOF_PTHREAD_COND_T];
+ __extension__ long long int __align __LOCK_ALIGNMENT;
+} cnd_t;
+
/* Threads functions. */
/* Create a new thread executing the function __FUNC. Arguments for __FUNC
@@ -140,6 +146,34 @@ extern void mtx_destroy (mtx_t *__mutex);
All calls must be made with the same __FLAGS object. */
extern void call_once (once_flag *__flag, void (*__func)(void));
+
+/* Condition variable functions. */
+
+/* Initialize new condition variable pointed by __COND. */
+extern int cnd_init (cnd_t *__cond);
+
+/* Unblock one thread that currently waits on condition variable pointed
+ by __COND. */
+extern int cnd_signal (cnd_t *__cond);
+
+/* Unblock all threads currently waiting on condition variable pointed by
+ __COND. */
+extern int cnd_broadcast (cnd_t *__cond);
+
+/* Block current thread on the condition variable pointed by __COND. */
+extern int cnd_wait (cnd_t *__cond, mtx_t *__mutex);
+
+/* Block current thread on the condition variable until condition variable
+ pointed by __COND is signaled or time pointed by __TIME_POINT is
+ reached. */
+extern int cnd_timedwait (cnd_t *__restrict __cond,
+ mtx_t *__restrict __mutex,
+ const struct timespec *__restrict __time_point);
+
+/* Destroy condition variable pointed by __cond and free all of its
+ resources. */
+extern void cnd_destroy (cnd_t *__COND);
+
__END_DECLS
#endif /* _THREADS_H */