mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH v3 0/5] Add posix/pthread_mutex_clocklock posix/pthread_cond_clockdwait c2y/mtx_timedlock_base c2y/cnd_timedwait_base
@ 2023-06-20 14:36 Yonggang Luo
  2023-06-20 14:36 ` [musl] [PATCH v3 1/5] trim spaces of pthread_cond_timedwait.c and pthread_mutex_timedlock.c Yonggang Luo
                   ` (5 more replies)
  0 siblings, 6 replies; 14+ messages in thread
From: Yonggang Luo @ 2023-06-20 14:36 UTC (permalink / raw)
  To: Jens Gustedt, enh, musl; +Cc: Yonggang Luo

Currently, musl doesn't have pthread_mutex_clocklock pthread_cond_clockdwait, but
glibc, android bionic, qnx libc already have these two functions, so implement them in
musl.

And for c11 threads, the mtx and cnd doesn't support for monotonic timedlock and timedwait;
So add a proposaled 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.

And indeed mtx_timedlock_base and cnd_timedwait_base  can be implemented ontop of
posix/pthread_mutex_clocklock posix/pthread_cond_clockdwait, so I implemented
posix/pthread_mutex_clocklock posix/pthread_cond_clockdwait first in musl.

I think mtx_timedlock_base cnd_timedwait_base is reasonable because it's newly added
function and won't affect existing c11 threads functions.
And it's can be implementd with glibc/qnx libc/android bionic without burden.
For OS X it's can be implemented with pthread_cond_timedwait_relative_np
For Windows it's can be implemented with SleepConditionVariableCS
For platform have none of these, it's still can fallback to using mtx_timedlock and cnd_timedwait
over TIME_UTC

Yonggang Luo (5):
  trim spaces of pthread_cond_timedwait.c and pthread_mutex_timedlock.c
  Rename files for implement pthread_mutex_clocklock and
    pthread_cond_clockwait
  add pthread_mutex_clocklock and pthread_cond_clockdwait
  c23: Implement newly base for timespec_get
  c2y: Add monotonic timedlock/timedwait support for threads mtx/cnd

 compat/time32/cnd_timedwait_base_time32.c     |   9 +
 compat/time32/mtx_timedlock_base_time32.c     |   9 +
 compat/time32/pthread_cond_clockwait_time32.c |   9 +
 .../time32/pthread_mutex_clocklock_time32.c   |   9 +
 compat/time32/time32.h                        |   4 +
 include/pthread.h                             |   4 +
 include/threads.h                             |   4 +
 include/time.h                                |  13 +-
 src/include/pthread.h                         |   2 +
 src/thread/cnd_timedwait.c                    |   8 +-
 src/thread/cnd_timedwait_base.c               |  26 +++
 src/thread/mtx_timedlock.c                    |   7 +-
 src/thread/mtx_timedlock_base.c               |  25 +++
 ...d_timedwait.c => pthread_cond_clockwait.c} |  14 +-
 src/thread/pthread_cond_timedwait.c           | 208 +-----------------
 ..._timedlock.c => pthread_mutex_clocklock.c} |  14 +-
 src/thread/pthread_mutex_timedlock.c          |  86 +-------
 src/time/timespec_get.c                       |  44 +++-
 18 files changed, 174 insertions(+), 321 deletions(-)
 create mode 100644 compat/time32/cnd_timedwait_base_time32.c
 create mode 100644 compat/time32/mtx_timedlock_base_time32.c
 create mode 100644 compat/time32/pthread_cond_clockwait_time32.c
 create mode 100644 compat/time32/pthread_mutex_clocklock_time32.c
 create mode 100644 src/thread/cnd_timedwait_base.c
 create mode 100644 src/thread/mtx_timedlock_base.c
 copy src/thread/{pthread_cond_timedwait.c => pthread_cond_clockwait.c} (93%)
 copy src/thread/{pthread_mutex_timedlock.c => pthread_mutex_clocklock.c} (85%)

-- 
2.39.0.windows.1


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-06-21 18:58 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-20 14:36 [musl] [PATCH v3 0/5] Add posix/pthread_mutex_clocklock posix/pthread_cond_clockdwait c2y/mtx_timedlock_base c2y/cnd_timedwait_base Yonggang Luo
2023-06-20 14:36 ` [musl] [PATCH v3 1/5] trim spaces of pthread_cond_timedwait.c and pthread_mutex_timedlock.c Yonggang Luo
2023-06-20 14:37 ` [musl] [PATCH v3 2/5] Rename files for implement pthread_mutex_clocklock and pthread_cond_clockwait Yonggang Luo
2023-06-20 14:37 ` [musl] [PATCH v3 3/5] add pthread_mutex_clocklock and pthread_cond_clockdwait Yonggang Luo
2023-06-21 15:04   ` Rich Felker
2023-06-20 14:37 ` [musl] [PATCH v3 4/5] c23: Implement newly base for timespec_get Yonggang Luo
2023-06-20 14:37 ` [musl] [PATCH v3 5/5] c2y: Add monotonic timedlock/timedwait support for threads mtx/cnd Yonggang Luo
2023-06-20 22:47 ` [musl] [PATCH v3 0/5] Add posix/pthread_mutex_clocklock posix/pthread_cond_clockdwait c2y/mtx_timedlock_base c2y/cnd_timedwait_base Rich Felker
2023-06-21  6:10   ` 罗勇刚(Yonggang Luo)
2023-06-21 14:54     ` Rich Felker
2023-06-21 18:43       ` 罗勇刚(Yonggang Luo)
2023-06-21 18:58         ` enh
2023-06-21  6:25   ` 罗勇刚(Yonggang Luo)
2023-06-21 14:44     ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).