From: Yonggang Luo <luoyonggang@gmail.com>
To: Jens Gustedt <jens.gustedt@inria.fr>, libc-alpha@sourceware.org
Cc: Florian Weimer <fweimer@redhat.com>,
Yonggang Luo <luoyonggang@gmail.com>
Subject: [PATCH v2 4/4] c2y: Add function cnd_timedwait_base and mtx_timedlock_base
Date: Wed, 21 Jun 2023 01:17:31 +0800 [thread overview]
Message-ID: <20230620171731.230-5-luoyonggang@gmail.com> (raw)
In-Reply-To: <20230620171731.230-1-luoyonggang@gmail.com>
For c11 threads, the mtx and cnd doesn't support for monotonic timedlock and timedwait;
So add two proposal function mtx_timedlock_base cnd_timedwait_base to do that.
The protype of these two functions is:
int mtx_timedlock_base(mtx_t *restrict m, int time_base, const struct timespec *restrict ts);
int cnd_timedwait_base(cnd_t *restrict c, mtx_t *restrict m, int time_base, const struct timespec *restrict ts);
The time_base at least can be TIME_UTC/TIME_MONOTONIC, the implementer can implement it with any provided
TIME_* base parameter provided in c2y time.h, if TIME_MONOTONIC can not natively supported, fallback to TIME_UTC
should provided, for other TIME_* base parameter, it's implementer's choice.
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
conform/data/threads.h-data | 2 +
htl/Versions | 5 ++
nptl/Versions | 5 ++
sysdeps/pthread/Makefile | 2 +
sysdeps/pthread/cnd_timedwait_base.c | 29 +++++++++++
sysdeps/pthread/mtx_timedlock_base.c | 28 +++++++++++
sysdeps/pthread/threads.h | 18 +++++++
sysdeps/unix/sysv/linux/Versions | 6 +++
sysdeps/unix/sysv/linux/cnd_timedwait_base.c | 53 ++++++++++++++++++++
sysdeps/unix/sysv/linux/mtx_timedlock_base.c | 50 ++++++++++++++++++
sysdeps/unix/sysv/linux/thrd_priv.h | 10 ++++
11 files changed, 208 insertions(+)
create mode 100644 sysdeps/pthread/cnd_timedwait_base.c
create mode 100644 sysdeps/pthread/mtx_timedlock_base.c
create mode 100644 sysdeps/unix/sysv/linux/cnd_timedwait_base.c
create mode 100644 sysdeps/unix/sysv/linux/mtx_timedlock_base.c
diff --git a/conform/data/threads.h-data b/conform/data/threads.h-data
index 406e497726..e938e0512c 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_base (mtx_t*, int, 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_base (cnd_t*, mtx_t*, int, const struct timespec*)
function void cnd_destroy (cnd_t*)
function int tss_create (tss_t*, tss_dtor_t)
diff --git a/htl/Versions b/htl/Versions
index 70fa44631a..804005bfb9 100644
--- a/htl/Versions
+++ b/htl/Versions
@@ -170,6 +170,11 @@ libpthread {
sem_clockwait;
}
+ GLIBC_2.38 {
+ cnd_timedwait_base;
+ mtx_timedlock_base;
+ }
+
GLIBC_PRIVATE {
__pthread_initialize_minimal;
diff --git a/nptl/Versions b/nptl/Versions
index 3221de89d1..d44ab2b12d 100644
--- a/nptl/Versions
+++ b/nptl/Versions
@@ -525,6 +525,11 @@ libpthread {
GLIBC_2.31 {
__libpthread_version_placeholder;
}
+
+ GLIBC_2.38 {
+ cnd_timedwait_base;
+ mtx_timedlock_base;
+ }
}
ld {
diff --git a/sysdeps/pthread/Makefile b/sysdeps/pthread/Makefile
index 32cf4eb119..a4a9d1b2cc 100644
--- a/sysdeps/pthread/Makefile
+++ b/sysdeps/pthread/Makefile
@@ -40,11 +40,13 @@ $(libpthread-routines-var) += \
cnd_init \
cnd_signal \
cnd_timedwait \
+ cnd_timedwait_base \
cnd_wait \
mtx_destroy \
mtx_init \
mtx_lock \
mtx_timedlock \
+ mtx_timedlock_base \
mtx_trylock \
mtx_unlock \
pthread_atfork_compat \
diff --git a/sysdeps/pthread/cnd_timedwait_base.c b/sysdeps/pthread/cnd_timedwait_base.c
new file mode 100644
index 0000000000..e9be66ca0e
--- /dev/null
+++ b/sysdeps/pthread/cnd_timedwait_base.c
@@ -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_base (cnd_t *restrict cond, mtx_t *restrict mutex, int time_base,
+ const struct timespec *restrict time_point)
+{
+ int err_code = __pthread_cond_clockwait ((pthread_cond_t *) cond,
+ (pthread_mutex_t *) mutex,
+ time_base, time_point);
+ return thrd_err_map (err_code);
+}
diff --git a/sysdeps/pthread/mtx_timedlock_base.c b/sysdeps/pthread/mtx_timedlock_base.c
new file mode 100644
index 0000000000..9aecf84440
--- /dev/null
+++ b/sysdeps/pthread/mtx_timedlock_base.c
@@ -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_base (mtx_t *restrict mutex, int time_base,
+ const struct timespec *restrict time_point)
+{
+ int err_code = __pthread_mutex_clocklock ((pthread_mutex_t *) mutex,
+ time_base, time_point);
+ return thrd_err_map (err_code);
+}
diff --git a/sysdeps/pthread/threads.h b/sysdeps/pthread/threads.h
index d88d7a3ddd..4f61ad9236 100644
--- a/sysdeps/pthread/threads.h
+++ b/sysdeps/pthread/threads.h
@@ -146,14 +146,22 @@ 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_base (mtx_t *__restrict __mutex, int time_base,
+ 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_base, (mtx_t *__restrict __mutex,
+ int time_base,
+ const struct timespec *__restrict
+ __time_point),
+ __mtx_timedlock_base64);
# else
# define mtx_timedlock __mtx_timedlock64
+# define mtx_timedlock_base __mtx_timedlock_base64
# endif
#endif
@@ -198,6 +206,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_base (cnd_t *__restrict __cond,
+ mtx_t *__restrict __mutex, int time_base,
+ const struct timespec *__restrict __time_point);
#else
# ifdef __REDIRECT
extern int __REDIRECT (cnd_timedwait, (cnd_t *__restrict __cond,
@@ -205,8 +216,15 @@ extern int __REDIRECT (cnd_timedwait, (cnd_t *__restrict __cond,
const struct timespec *__restrict
__time_point),
__cnd_timedwait64);
+extern int __REDIRECT (cnd_timedwait_base, (cnd_t *__restrict __cond,
+ mtx_t *__restrict __mutex,
+ int time_base,
+ const struct timespec *__restrict
+ __time_point),
+ __cnd_timedwait_base64);
# else
# define cnd_timedwait __cnd_timedwait64
+# define cnd_timedwait_base __cnd_timedwait_base64
# endif
#endif
diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions
index bc59bce42f..73ce24bea6 100644
--- a/sysdeps/unix/sysv/linux/Versions
+++ b/sysdeps/unix/sysv/linux/Versions
@@ -319,6 +319,12 @@ libc {
GLIBC_2.37 {
%ifdef TIME64_NON_DEFAULT
__ppoll64_chk;
+%endif
+ }
+ GLIBC_2.38 {
+%ifdef TIME64_NON_DEFAULT
+ __cnd_timedwait_base64;
+ __mtx_timedlock_base64;
%endif
}
GLIBC_PRIVATE {
diff --git a/sysdeps/unix/sysv/linux/cnd_timedwait_base.c b/sysdeps/unix/sysv/linux/cnd_timedwait_base.c
new file mode 100644
index 0000000000..2e851a7aec
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/cnd_timedwait_base.c
@@ -0,0 +1,53 @@
+/* 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_base64 (cnd_t *restrict cond, mtx_t *restrict mutex,
+ int time_base,
+ const struct __timespec64 *restrict time_point)
+{
+ int err_code = __pthread_cond_clockwait64 ((pthread_cond_t *) cond,
+ (pthread_mutex_t *) mutex,
+ time_base, time_point);
+ return thrd_err_map (err_code);
+}
+
+#if __TIMESIZE == 64
+strong_alias (__cnd_timedwait_base64, ___cnd_timedwait_base)
+#else
+libc_hidden_def (__cnd_timedwait_base64)
+
+int
+___cnd_timedwait_base (cnd_t *restrict cond, mtx_t *restrict mutex,
+ int time_base,
+ const struct timespec *restrict time_point)
+{
+ struct __timespec64 ts64 = valid_timespec_to_timespec64 (*time_point);
+
+ return __cnd_timedwait_base64 (cond, mutex, time_base, &ts64);
+}
+#endif /* __TIMESIZE == 64 */
+versioned_symbol (libc, ___cnd_timedwait_base, cnd_timedwait_base, GLIBC_2_34);
+
+#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_28, GLIBC_2_34)
+compat_symbol (libpthread, ___cnd_timedwait_base, cnd_timedwait_base, GLIBC_2_28);
+#endif
diff --git a/sysdeps/unix/sysv/linux/mtx_timedlock_base.c b/sysdeps/unix/sysv/linux/mtx_timedlock_base.c
new file mode 100644
index 0000000000..046fb86091
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/mtx_timedlock_base.c
@@ -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_base64 (mtx_t *restrict mutex, int time_base,
+ const struct __timespec64 *restrict time_point)
+{
+ int err_code = __pthread_mutex_clocklock64 ((pthread_mutex_t *) mutex,
+ time_base, time_point);
+ return thrd_err_map (err_code);
+}
+
+#if __TIMESIZE == 64
+strong_alias (__mtx_timedlock_base64, ___mtx_timedlock_base)
+#else
+libc_hidden_def (__mtx_timedlock_base64)
+
+int
+___mtx_timedlock_base (mtx_t *restrict mutex, int time_base,
+ const struct timespec *restrict time_point)
+{
+ struct __timespec64 ts64 = valid_timespec_to_timespec64 (*time_point);
+
+ return __mtx_timedlock_base64 (mutex, time_base, &ts64);
+}
+#endif /* __TIMESIZE == 64 */
+versioned_symbol (libc, ___mtx_timedlock_base, mtx_timedlock_base, GLIBC_2_34);
+
+#if OTHER_SHLIB_COMPAT (libpthread, GLIBC_2_28, GLIBC_2_34)
+compat_symbol (libpthread, ___mtx_timedlock_base, mtx_timedlock_base, GLIBC_2_28);
+#endif
diff --git a/sysdeps/unix/sysv/linux/thrd_priv.h b/sysdeps/unix/sysv/linux/thrd_priv.h
index af23a10a07..8ea9ced507 100644
--- a/sysdeps/unix/sysv/linux/thrd_priv.h
+++ b/sysdeps/unix/sysv/linux/thrd_priv.h
@@ -20,15 +20,25 @@
#if __TIMESIZE == 64
# define __cnd_timedwait64 __cnd_timedwait
+# define __cnd_timedwait_base64 __cnd_timedwait_base
# define __mtx_timedlock64 __mtx_timedlock
+# define __mtx_timedlock_base64 __mtx_timedlock_base
# 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_base64 (cnd_t *restrict cond, mtx_t *restrict mutex,
+ int time_base,
+ const struct __timespec64 *restrict time_point);
+libc_hidden_proto (__cnd_timedwait_base64)
extern int __mtx_timedlock64 (mtx_t *restrict mutex,
const struct __timespec64 *restrict time_point);
libc_hidden_proto (__mtx_timedlock64)
+extern int __mtx_timedlock_base64 (mtx_t *restrict mutex, int time_base,
+ const struct __timespec64 *restrict
+ time_point);
+libc_hidden_proto (__mtx_timedlock_base64)
extern int __thrd_sleep64 (const struct __timespec64 *time_point,
struct __timespec64 *remaining);
libc_hidden_proto (__thrd_sleep64)
--
2.39.0.windows.1
next prev parent reply other threads:[~2023-06-20 17:17 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-20 17:17 [PATCH v2 0/4] c2y proposal add monotonicwait support for mtx and ctx Yonggang Luo
2023-06-20 17:17 ` [PATCH v2 1/4] clang-format: should format with 2 space and do not usage tab Yonggang Luo
2023-06-20 17:45 ` Zack Weinberg
2023-06-21 6:31 ` 罗勇刚(Yonggang Luo)
2023-06-21 6:47 ` Xi Ruoyao
2023-06-21 6:55 ` 罗勇刚(Yonggang Luo)
2023-06-21 7:13 ` Xi Ruoyao
2023-06-21 7:36 ` 罗勇刚(Yonggang Luo)
2023-06-21 14:26 ` Zack Weinberg
2023-06-21 7:17 ` Xi Ruoyao
2023-06-21 16:19 ` Carlos O'Donell
2023-06-21 17:35 ` Joseph Myers
2023-06-21 17:41 ` 罗勇刚(Yonggang Luo)
2023-06-21 17:49 ` Andrew Pinski
2023-06-21 17:59 ` 罗勇刚(Yonggang Luo)
2023-06-21 18:31 ` Arsen Arsenović
2023-06-21 18:42 ` 罗勇刚(Yonggang Luo)
2023-06-21 19:36 ` Zack Weinberg
2023-06-21 21:26 ` Paul Eggert
2023-06-22 21:43 ` Joseph Myers
2023-06-22 21:48 ` Paul Eggert
2023-06-20 17:17 ` [PATCH v2 2/4] time: Implement c23 timespec_get base Yonggang Luo
2023-06-20 20:37 ` Joseph Myers
2023-06-21 6:42 ` 罗勇刚(Yonggang Luo)
2023-06-20 17:17 ` [PATCH v2 3/4] c11: Switch to use pthread_mutex_clocklock and pthread_cond_clockwait to implement cnd and mtx lock and wait Yonggang Luo
2023-06-20 17:17 ` Yonggang Luo [this message]
2023-06-20 20:41 ` [PATCH v2 4/4] c2y: Add function cnd_timedwait_base and mtx_timedlock_base Joseph Myers
2023-06-21 9:21 ` 罗勇刚(Yonggang Luo)
2023-06-21 9:54 ` Xi Ruoyao
2023-06-21 10:16 ` 罗勇刚(Yonggang Luo)
2023-06-21 10:25 ` Xi Ruoyao
2023-06-21 10:40 ` Florian Weimer
2023-06-21 13:23 ` Jₑₙₛ Gustedt
2023-06-21 12:09 ` Joseph Myers
2023-06-21 14:30 ` enh
2023-06-21 15:08 ` Joseph Myers
2023-06-21 18:39 ` 罗勇刚(Yonggang Luo)
2023-06-21 19:04 ` enh
2023-06-21 19:07 ` 罗勇刚(Yonggang Luo)
2023-06-21 19:18 ` enh
2023-06-21 19:38 ` 罗勇刚(Yonggang Luo)
2023-06-21 19:41 ` enh
2023-06-21 20:14 ` 罗勇刚(Yonggang Luo)
2023-06-21 19:43 ` 罗勇刚(Yonggang Luo)
2023-06-20 20:50 ` Joseph Myers
2023-06-20 20:45 ` [PATCH v2 0/4] c2y proposal add monotonicwait support for mtx and ctx Joseph Myers
2023-06-21 6:52 ` 罗勇刚(Yonggang Luo)
2023-06-21 7:14 ` Xi Ruoyao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230620171731.230-5-luoyonggang@gmail.com \
--to=luoyonggang@gmail.com \
--cc=fweimer@redhat.com \
--cc=jens.gustedt@inria.fr \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).