On Tue, 20 Jun 2023, Yonggang Luo via Libc-alpha wrote:
> diff --git a/conform/data/threads.h-data b/conform/data/threads.h-data
> index 406e497726..cb71ddfaf7 100644
> --- a/conform/data/threads.h-data
> +++ b/conform/data/threads.h-data
> @@ -34,6 +34,7 @@ function void thrd_yield (void)
> function int mtx_init (mtx_t*, int)
> function int mtx_lock (mtx_t*)
> function int mtx_timedlock (mtx_t*, const struct timespec*)
> +function int mtx_timedlock_monotonic (mtx_t*, const struct timespec*)
> function int mtx_trylock (mtx_t*)
> function int mtx_unlock (mtx_t*)
> function void mtx_destroy (mtx_t*)
> @@ -45,6 +46,7 @@ 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 int cnd_timedwait_monotonic (cnd_t*, mtx_t*, const struct timespec*)
> function void cnd_destroy (cnd_t*)
No, conform/* shows what is in an actual standard, not glibc inventions
that might be in some future standard, and everything in those data files
is conditioned based on exactly what supported standards contain it -
you're changing a section of C11 functions to add things that aren't in
C11 or any standard at all. We haven't yet added C2x support to conform/*
(that should wait for C2x support to be completed in glibc as well as for
the technical content of C2x to be finalized, changes to the expected
header contents are still going into C2x), and at that point, C2x
additions would be conditioned on defined ISO24 or similar, C2y (only once
that's finalized etc.) on defined ISO27 or similar.
> diff --git a/sysdeps/pthread/threads.h b/sysdeps/pthread/threads.h
> index d88d7a3ddd..b3ddaafd05 100644
> --- a/sysdeps/pthread/threads.h
> +++ b/sysdeps/pthread/threads.h
> @@ -146,14 +146,21 @@ extern int mtx_lock (mtx_t *__mutex);
> #ifndef __USE_TIME_BITS64
> extern int mtx_timedlock (mtx_t *__restrict __mutex,
> const struct timespec *__restrict __time_point);
> +extern int mtx_timedlock_monotonic (mtx_t *__restrict __mutex,
> + const struct timespec *__restrict __time_point);
New functions like this should be conditioned on __USE_GNU in the headers
(even when in a reserved namespace other than __*).
@@ -34,6 +34,7 @@ function void thrd_yield (void)
function int mtx_init (mtx_t*, int)
function int mtx_lock (mtx_t*)
function int mtx_timedlock (mtx_t*, const struct timespec*)
+function int mtx_timedlock_monotonic (mtx_t*, const struct timespec*)
function int mtx_trylock (mtx_t*)
function int mtx_unlock (mtx_t*)
function void mtx_destroy (mtx_t*)
@@ -45,6 +46,7 @@ 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 int cnd_timedwait_monotonic (cnd_t*, mtx_t*, const struct timespec*)
function void cnd_destroy (cnd_t*)
function int tss_create (tss_t*, tss_dtor_t)
@@ -525,6 +525,11 @@ libpthread {
GLIBC_2.31 {
__libpthread_version_placeholder;
}
+
+ GLIBC_2.38 {
+ cnd_timedwait_monotonic;
+ mtx_timedlock_monotonic;
+ }
}
ld {
@@ -40,11 +40,13 @@ $(libpthread-routines-var) += \
cnd_init \
cnd_signal \
cnd_timedwait \
+ cnd_timedwait_monotonic \
cnd_wait \
mtx_destroy \
mtx_init \
mtx_lock \
mtx_timedlock \
+ mtx_timedlock_monotonic \
mtx_trylock \
mtx_unlock \
pthread_atfork_compat \
new file mode 100644
@@ -0,0 +1,29 @@
+/* C11 threads conditional timed wait implementation.
+ Copyright (C) 2018-2023 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_monotonic (cnd_t *restrict cond, mtx_t *restrict mutex,
+ const struct timespec *restrict time_point)
+{
+ int err_code = __pthread_cond_clockwait ((pthread_cond_t *) cond,
+ (pthread_mutex_t *) mutex,
+ CLOCK_MONOTONIC, time_point);
+ return thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,28 @@
+/* C11 threads mutex timed lock implementation.
+ Copyright (C) 2018-2023 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_timedlock_monotonic (mtx_t *restrict mutex,
+ const struct timespec *restrict time_point)
+{
+ int err_code = pthread_mutex_clocklock ((pthread_mutex_t *) mutex,
+ CLOCK_MONOTONIC, time_point);
+ return thrd_err_map (err_code);
+}
@@ -146,14 +146,21 @@ extern int mtx_lock (mtx_t *__mutex);
#ifndef __USE_TIME_BITS64
extern int mtx_timedlock (mtx_t *__restrict __mutex,
const struct timespec *__restrict __time_point);
+extern int mtx_timedlock_monotonic (mtx_t *__restrict __mutex,
+ const struct timespec *__restrict __time_point);
#else
# ifdef __REDIRECT
extern int __REDIRECT (mtx_timedlock, (mtx_t *__restrict __mutex,
const struct timespec *__restrict
__time_point),
__mtx_timedlock64);
+extern int __REDIRECT (mtx_timedlock_monotonic, (mtx_t *__restrict __mutex,
+ const struct timespec *__restrict
+ __time_point),
+ __mtx_timedlock_monotonic64);
# else
# define mtx_timedlock __mtx_timedlock64
+# define mtx_timedlock_monotonic __mtx_timedlock_monotonic64
# endif
#endif
@@ -198,6 +205,9 @@ extern int cnd_wait (cnd_t *__cond, mtx_t *__mutex);
extern int cnd_timedwait (cnd_t *__restrict __cond,
mtx_t *__restrict __mutex,
const struct timespec *__restrict __time_point);
+extern int cnd_timedwait_monotonic (cnd_t *__restrict __cond,
+ mtx_t *__restrict __mutex,
+ const struct timespec *__restrict __time_point);
#else
# ifdef __REDIRECT
extern int __REDIRECT (cnd_timedwait, (cnd_t *__restrict __cond,
@@ -205,8 +215,14 @@ extern int __REDIRECT (cnd_timedwait, (cnd_t *__restrict __cond,
const struct timespec *__restrict
__time_point),
__cnd_timedwait64);
+extern int __REDIRECT (cnd_timedwait_monotonic, (cnd_t *__restrict __cond,
+ mtx_t *__restrict __mutex,
+ const struct timespec *__restrict
+ __time_point),
+ __cnd_timedwait_monotonic64);
# else
# define cnd_timedwait __cnd_timedwait64
+# define cnd_timedwait_monotonic __cnd_timedwait_monotonic64
# endif
#endif
@@ -319,6 +319,12 @@ libc {
GLIBC_2.37 {
%ifdef TIME64_NON_DEFAULT
__ppoll64_chk;
+%endif
+ }
+ GLIBC_2.38 {
+%ifdef TIME64_NON_DEFAULT
+ __cnd_timedwait_monotonic64;
+ __mtx_timedlock_monotonic64;
%endif
}
GLIBC_PRIVATE {
new file mode 100644
@@ -0,0 +1,51 @@
+/* C11 threads conditional timed wait implementation - Linux variant.
+ Copyright (C) 2020-2023 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 <time.h>
+#include <shlib-compat.h>
+#include "thrd_priv.h"
+
+int
+__cnd_timedwait_monotonic64 (cnd_t *restrict cond, mtx_t *restrict mutex,
+ const struct __timespec64 *restrict time_point)
+{
+ int err_code = __pthread_cond_clockwait64 ((pthread_cond_t *) cond,
+ (pthread_mutex_t *) mutex,
+ CLOCK_MONOTONIC, time_point);
+ return thrd_err_map (err_code);
+}
+
+#if __TIMESIZE == 64
+strong_alias (__cnd_timedwait_monotonic64, ___cnd_timedwait_monotonic)
+#else
+libc_hidden_def (__cnd_timedwait_monotonic64)
+
+int
+___cnd_timedwait_monotonic (cnd_t *restrict cond, mtx_t *restrict mutex,
+ const struct timespec *restrict time_point)
+{
+ struct __timespec64 ts64 = valid_timespec_to_timespec64 (*time_point);
+
+ return __cnd_timedwait_monotonic64(cond, mutex, &ts64);
+}
+#endif /* __TIMESIZE == 64 */
+versioned_symbol (libc, ___cnd_timedwait_monotonic, cnd_timedwait_monotonic, GLIBC_2_34);
+
+#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_28, GLIBC_2_34)
+compat_symbol (libpthread, ___cnd_timedwait_monotonic, cnd_timedwait_monotonic, GLIBC_2_28);
+#endif
new file mode 100644
@@ -0,0 +1,50 @@
+/* C11 threads mutex timed lock implementation - Linux variant.
+ Copyright (C) 2020-2023 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 <time.h>
+#include <shlib-compat.h>
+#include "thrd_priv.h"
+
+int
+__mtx_timedlock_monotonic64 (mtx_t *restrict mutex,
+ const struct __timespec64 *restrict time_point)
+{
+ int err_code = __pthread_mutex_clocklock64 ((pthread_mutex_t *) mutex,
+ CLOCK_MONOTONIC, time_point);
+ return thrd_err_map (err_code);
+}
+
+#if __TIMESIZE == 64
+strong_alias (__mtx_timedlock_monotonic64, ___mtx_timedlock_monotonic)
+#else
+libc_hidden_def (__mtx_timedlock_monotonic64)
+
+int
+___mtx_timedlock_monotonic (mtx_t *restrict mutex,
+ const struct timespec *restrict time_point)
+{
+ struct __timespec64 ts64 = valid_timespec_to_timespec64 (*time_point);
+
+ return __mtx_timedlock_monotonic64 (mutex, &ts64);
+}
+#endif /* __TIMESIZE == 64 */
+versioned_symbol (libc, ___mtx_timedlock_monotonic, mtx_timedlock_monotonic, GLIBC_2_34);
+
+#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_28, GLIBC_2_34)
+compat_symbol (libpthread, ___mtx_timedlock_monotonic, mtx_timedlock_monotonic, GLIBC_2_28);
+#endif
@@ -20,15 +20,23 @@
#if __TIMESIZE == 64
# define __cnd_timedwait64 __cnd_timedwait
+# define __cnd_timedwait_monotonic64 __cnd_timedwait_monotonic
# define __mtx_timedlock64 __mtx_timedlock
+# define __mtx_timedlock_monotonic64 __mtx_timedlock_monotonic
# define __thrd_sleep64 __thrd_sleep
#else
extern int __cnd_timedwait64 (cnd_t *restrict cond, mtx_t *restrict mutex,
const struct __timespec64 *restrict time_point);
libc_hidden_proto (__cnd_timedwait64)
+extern int __cnd_timedwait_monotonic64 (cnd_t *restrict cond, mtx_t *restrict mutex,
+ const struct __timespec64 *restrict time_point);
+libc_hidden_proto (__cnd_timedwait_monotonic64)
extern int __mtx_timedlock64 (mtx_t *restrict mutex,
const struct __timespec64 *restrict time_point);
libc_hidden_proto (__mtx_timedlock64)
+extern int __mtx_timedlock_monotonic64 (mtx_t *restrict mutex,
+ const struct __timespec64 *restrict time_point);
+libc_hidden_proto (__mtx_timedlock_monotonic64)
extern int __thrd_sleep64 (const struct __timespec64 *time_point,
struct __timespec64 *remaining);
libc_hidden_proto (__thrd_sleep64)