@@ -16,6 +16,7 @@ type thrd_t
type thrd_start_t
type mtx_t
type once_flag
+type cnd_t
function int thrd_create (thrd_t*, thrd_start_t, void*)
function int thrd_equal (thrd_t, thrd_t)
@@ -35,6 +36,13 @@ function void mtx_destroy (mtx_t*)
function void call_once (once_flag*, void (*)(void))
+function int cnd_init (cnd_t*)
+function int cnd_signal (cnd_t*)
+function int cnd_broadcast (cnd_t*)
+function int cnd_wait (cnd_t*, mtx_t*)
+function int cnd_timedwait (cnd_t*, mtx_t*, const struct timespec*)
+function void cnd_destroy (cnd_t*)
+
#include "time.h-data"
#endif
@@ -142,7 +142,8 @@ libpthread-routines = nptl-init vars events version pt-interp \
thrd_create thrd_current thrd_detach thrd_equal \
thrd_exit thrd_join thrd_sleep thrd_yield \
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 \
@@ -269,7 +269,8 @@ libpthread {
GLIBC_2.26 {
thrd_create; thrd_current; thrd_detach; thrd_equal; thrd_exit; thrd_join;
thrd_sleep; thrd_yield; mtx_init; mtx_lock; mtx_timedlock; mtx_trylock;
- mtx_unlock; mtx_destroy; call_once;
+ mtx_unlock; mtx_destroy; call_once; cnd_broadcast; cnd_destroy; cnd_init;
+ cnd_signal; cnd_timedwait; cnd_wait; mtx_destroy;
}
GLIBC_PRIVATE {
new file mode 100644
@@ -0,0 +1,28 @@
+/* C11 thread conditional broadcast implementation.
+ Copyright (C) 2017 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"
+
+/* Unblock all threads currently waiting on condition variable pointed
+ by cond. */
+int
+cnd_broadcast (cnd_t *cond)
+{
+ int err_code = __pthread_cond_broadcast ((pthread_cond_t*) cond);
+ return thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,28 @@
+/* C11 threads conditional destroy implementation.
+ Copyright (C) 2017 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"
+
+/* Destroy condition variable pointed by cond and free all of its
+ resources. */
+void
+cnd_destroy (cnd_t *cond)
+{
+ __pthread_cond_destroy ((pthread_cond_t *) cond);
+}
new file mode 100644
@@ -0,0 +1,27 @@
+/* C11 thread conditional initialization implementation.
+ Copyright (C) 2017 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"
+
+/* Initialize new condition variable pointed by cond. */
+int
+cnd_init (cnd_t *cond)
+{
+ int err_code = __pthread_cond_init ((pthread_cond_t *)cond, NULL);
+ return thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,28 @@
+/* C11 threads conditional signal implementation.
+ Copyright (C) 2017 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"
+
+/* Unblock one thread that currently waits on condition variable pointed
+ by cond. */
+int
+cnd_signal (cnd_t *cond)
+{
+ int err_code = __pthread_cond_signal ((pthread_cond_t *) cond);
+ return thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,31 @@
+/* C11 threads conditional timed wait implementation.
+ Copyright (C) 2017 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"
+
+/* Block current thread on the condition variable until condition variable
+ pointed by cond is signaled or time pointed by time_point is reached. */
+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);
+}
new file mode 100644
@@ -0,0 +1,28 @@
+/* C11 threads conditional wait implementaiton.
+ Copyright (C) 2017 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"
+
+/* Block current thread on the condition variable pointed by cond. */
+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);
+}
@@ -58,6 +58,13 @@ typedef union
long int __align;
} mtx_t;
+typedef union
+{
+ struct __pthread_cond_s __data;
+ char __size[__SIZEOF_PTHREAD_COND_T];
+ __extension__ long long int __align;
+} cnd_t;
+
/* Threads functions. */
/* Create a new thread executing the function __func. Arguments to __func
@@ -137,6 +144,34 @@ extern void mtx_destroy (mtx_t *__mutex);
All calls must be made with the same __flag 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 */