|
Message-Id: <20230620143703.1415-1-luoyonggang@gmail.com> Date: Tue, 20 Jun 2023 22:36:58 +0800 From: Yonggang Luo <luoyonggang@...il.com> To: Jens Gustedt <jens.gustedt@...ia.fr>, enh <enh@...gle.com>, musl@...ts.openwall.com Cc: Yonggang Luo <luoyonggang@...il.com> Subject: [PATCH v3 0/5] Add posix/pthread_mutex_clocklock posix/pthread_cond_clockdwait c2y/mtx_timedlock_base c2y/cnd_timedwait_base 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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.