From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 4433 invoked from network); 20 Jun 2023 00:26:16 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 20 Jun 2023 00:26:16 -0000 Received: (qmail 7504 invoked by uid 550); 20 Jun 2023 00:25:44 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 7434 invoked from network); 20 Jun 2023 00:25:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687220731; x=1689812731; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rvGbn0g1j4vq/XAi96Nc67gUP8ckvR0+1iu5zwTfq8c=; b=KACaXmF1K2l41HXzXcKThGmRUG6AevZdZBLebxvuznJrLq9hBmmwP07SvsEvGoQb0w 3k4rMwiI2Uivf7T/O0hmIGR5DZnKy3HGPNSQ8uk3b8WF9IRcusbSajwnf1uLZSpAWmWE JfJHK2iewqscQZWiH2mwwU1S0pcHbfaqG6d3zNJTbGQiagnyFpkQ4OqKQx/KKw5kYjVT 22pb9g9NY6vn1fu62RaQJF6yzqYlKXcRUisqCtoDeWhU0y0gcSI574bc+sFUanLXeP39 XmUhujxyIBIT66hig3g/ZfgD7yXisKEKNNZsyH2IPHCFZxHlNGCvHTl4KFMH8bKDrZ2N dnZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687220731; x=1689812731; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rvGbn0g1j4vq/XAi96Nc67gUP8ckvR0+1iu5zwTfq8c=; b=lAsqkJbLz1PZhyJxqrFALAXxJ4Og5GnGdNePekzCjqCzSGs+A5mHcj+9x65FB5oLGK 4khP0t3DR2ek7tVy+++i6sd+mQSGgjVSo0DN4E2xA93ckqlG473VXzKn+w3ITSr+SBFe Y2wlnRIeEHWvh1WhM9HneOmZt2UWYmjWtLCuGn2+IHJxPeIngjHzmqOiN/7Ioa04O3Tx 3meZhodMLZexU0yWZGWRIlweYGRFBSJdejoAUfN9i14labdTTXjPeFdJ5k25jIJ/RzFZ ot9IrB/FLJINptU7cy3fsEwSg/pHx5wQnBHoL5HiFzwTAhfWjIBc7RqpBRRXp6yD9b52 SRDg== X-Gm-Message-State: AC+VfDwnd0R+rfd/rj8hxqq8339o8QND2Kt2vPhwzhU1tyC+kgoATOQl 2Za2NZ4Z+3FXOL502pDUtDw= X-Google-Smtp-Source: ACHHUZ69yVlebFjl5yaxj8ip5FQ9vJMs8tLFZQSCcChex51mLzNsyhgyZS1eacozoV8Pfgd7kQg0+g== X-Received: by 2002:a05:6359:679e:b0:130:df70:b9cd with SMTP id sq30-20020a056359679e00b00130df70b9cdmr2516448rwb.12.1687220731257; Mon, 19 Jun 2023 17:25:31 -0700 (PDT) From: Yonggang Luo To: Jens Gustedt , musl@lists.openwall.com Cc: Yonggang Luo Date: Tue, 20 Jun 2023 08:25:07 +0800 Message-Id: <20230620002507.796-5-luoyonggang@gmail.com> X-Mailer: git-send-email 2.39.0.windows.1 In-Reply-To: <20230620002507.796-1-luoyonggang@gmail.com> References: <20230620002507.796-1-luoyonggang@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: [musl] [PATCH 4/4] c2y: Add monotonic timed wait support for threads mtx cnd Add two monotonic functions: mtx_timedlock_monotonic cnd_timedwait_monotonic to achieve that Signed-off-by: Yonggang Luo --- .../time32/cnd_timedwait_monotonic_time32.c | 9 ++++++ .../time32/mtx_timedlock_monotonic_time32.c | 9 ++++++ compat/time32/time32.h | 2 ++ include/threads.h | 4 +++ src/thread/cnd_timedwait.c | 2 +- ..._timedwait.c =3D> cnd_timedwait_monotonic.c} | 28 +++++++++---------- src/thread/mtx_timedlock.c | 2 +- ..._timedlock.c =3D> mtx_timedlock_monotonic.c} | 26 ++++++++--------- 8 files changed, 53 insertions(+), 29 deletions(-) create mode 100644 compat/time32/cnd_timedwait_monotonic_time32.c create mode 100644 compat/time32/mtx_timedlock_monotonic_time32.c copy src/thread/{cnd_timedwait.c =3D> cnd_timedwait_monotonic.c} (52%) copy src/thread/{mtx_timedlock.c =3D> mtx_timedlock_monotonic.c} (74%) diff --git a/compat/time32/cnd_timedwait_monotonic_time32.c b/compat/time32= /cnd_timedwait_monotonic_time32.c new file mode 100644 index 00000000..a61cc944 --- /dev/null +++ b/compat/time32/cnd_timedwait_monotonic_time32.c @@ -0,0 +1,9 @@ +#include "time32.h" +#include +#include + +int __cnd_timedwait_monotonic_time32(cnd_t *restrict c, mtx_t *restrict m,= const struct timespec32 *restrict ts32) +{ + return cnd_timedwait_monotonic(c, m, ts32 ? (&(struct timespec){ + .tv_sec =3D ts32->tv_sec, .tv_nsec =3D ts32->tv_nsec}) : 0); +} diff --git a/compat/time32/mtx_timedlock_monotonic_time32.c b/compat/time32= /mtx_timedlock_monotonic_time32.c new file mode 100644 index 00000000..fb610ab8 --- /dev/null +++ b/compat/time32/mtx_timedlock_monotonic_time32.c @@ -0,0 +1,9 @@ +#include "time32.h" +#include +#include + +int __mtx_timedlock_monotonic_time32(mtx_t *restrict m, const struct times= pec32 *restrict ts32) +{ + return mtx_timedlock_monotonic(m, !ts32 ? 0 : (&(struct timespec){ + .tv_sec =3D ts32->tv_sec, .tv_nsec =3D ts32->tv_nsec})); +} diff --git a/compat/time32/time32.h b/compat/time32/time32.h index e0af9bff..c98c4a64 100644 --- a/compat/time32/time32.h +++ b/compat/time32/time32.h @@ -34,6 +34,7 @@ int __clock_gettime32() __asm__("clock_gettime"); int __clock_nanosleep_time32() __asm__("clock_nanosleep"); int __clock_settime32() __asm__("clock_settime"); int __cnd_timedwait_time32() __asm__("cnd_timedwait"); +int __cnd_timedwait_monotonic_time32() __asm__("cnd_timedwait_monotonic"); char *__ctime32() __asm__("ctime"); char *__ctime32_r() __asm__("ctime_r"); double __difftime32() __asm__("difftime"); @@ -56,6 +57,7 @@ time32_t __mktime32() __asm__("mktime"); ssize_t __mq_timedreceive_time32() __asm__("mq_timedreceive"); int __mq_timedsend_time32() __asm__("mq_timedsend"); int __mtx_timedlock_time32() __asm__("mtx_timedlock"); +int __mtx_timedlock_monotonic_time32() __asm__("mtx_timedlock_monotonic"); int __nanosleep_time32() __asm__("nanosleep"); int __ppoll_time32() __asm__("ppoll"); int __pselect_time32() __asm__("pselect"); diff --git a/include/threads.h b/include/threads.h index 52ec3100..9439d530 100644 --- a/include/threads.h +++ b/include/threads.h @@ -62,6 +62,7 @@ void mtx_destroy(mtx_t *); =20 int mtx_lock(mtx_t *); int mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict); +int mtx_timedlock_monotonic(mtx_t *__restrict, const struct timespec *__re= strict); int mtx_trylock(mtx_t *); int mtx_unlock(mtx_t *); =20 @@ -72,6 +73,7 @@ int cnd_broadcast(cnd_t *); int cnd_signal(cnd_t *); =20 int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict, const struct times= pec *__restrict); +int cnd_timedwait_monotonic(cnd_t *__restrict, mtx_t *__restrict, const st= ruct timespec *__restrict); int cnd_wait(cnd_t *, mtx_t *); =20 int tss_create(tss_t *, tss_dtor_t); @@ -83,7 +85,9 @@ void *tss_get(tss_t); #if _REDIR_TIME64 __REDIR(thrd_sleep, __thrd_sleep_time64); __REDIR(mtx_timedlock, __mtx_timedlock_time64); +__REDIR(mtx_timedlock_monotonic, __mtx_timedlock_monotonic_time64); __REDIR(cnd_timedwait, __cnd_timedwait_time64); +__REDIR(cnd_timedwait_monotonic, __cnd_timedwait_monotonic_time64); #endif =20 #ifdef __cplusplus diff --git a/src/thread/cnd_timedwait.c b/src/thread/cnd_timedwait.c index 2802af52..8c951e0f 100644 --- a/src/thread/cnd_timedwait.c +++ b/src/thread/cnd_timedwait.c @@ -4,7 +4,7 @@ =20 int cnd_timedwait(cnd_t *restrict c, mtx_t *restrict m, const struct times= pec *restrict ts) { - int ret =3D __pthread_cond_timedwait((pthread_cond_t *)c, (pthread_mutex_= t *)m, ts); + int ret =3D pthread_cond_clockdwait((pthread_cond_t *)c, (pthread_mutex_t= *)m, CLOCK_REALTIME, ts); switch (ret) { /* May also return EINVAL or EPERM. */ default: return thrd_error; diff --git a/src/thread/cnd_timedwait.c b/src/thread/cnd_timedwait_monotoni= c.c similarity index 52% copy from src/thread/cnd_timedwait.c copy to src/thread/cnd_timedwait_monotonic.c index 2802af52..a7fe2fd6 100644 --- a/src/thread/cnd_timedwait.c +++ b/src/thread/cnd_timedwait_monotonic.c @@ -1,14 +1,14 @@ -#include -#include -#include - -int cnd_timedwait(cnd_t *restrict c, mtx_t *restrict m, const struct times= pec *restrict ts) -{ - int ret =3D __pthread_cond_timedwait((pthread_cond_t *)c, (pthread_mutex_= t *)m, ts); - switch (ret) { - /* May also return EINVAL or EPERM. */ - default: return thrd_error; - case 0: return thrd_success; - case ETIMEDOUT: return thrd_timedout; - } -} +#include =0D +#include =0D +#include =0D +=0D +int cnd_timedwait_monotonic(cnd_t *restrict c, mtx_t *restrict m, const st= ruct timespec *restrict ts)=0D +{=0D + int ret =3D pthread_cond_clockdwait((pthread_cond_t *)c, (pthread_mutex_t= *)m, CLOCK_MONOTONIC, ts);=0D + switch (ret) {=0D + /* May also return EINVAL or EPERM. */=0D + default: return thrd_error;=0D + case 0: return thrd_success;=0D + case ETIMEDOUT: return thrd_timedout;=0D + }=0D +}=0D diff --git a/src/thread/mtx_timedlock.c b/src/thread/mtx_timedlock.c index d22c8cf4..30dba40e 100644 --- a/src/thread/mtx_timedlock.c +++ b/src/thread/mtx_timedlock.c @@ -4,7 +4,7 @@ =20 int mtx_timedlock(mtx_t *restrict m, const struct timespec *restrict ts) { - int ret =3D __pthread_mutex_timedlock((pthread_mutex_t *)m, ts); + int ret =3D pthread_mutex_clocklock((pthread_mutex_t *)m, CLOCK_REALTIME,= ts); switch (ret) { default: return thrd_error; case 0: return thrd_success; diff --git a/src/thread/mtx_timedlock.c b/src/thread/mtx_timedlock_monotoni= c.c similarity index 74% copy from src/thread/mtx_timedlock.c copy to src/thread/mtx_timedlock_monotonic.c index d22c8cf4..a788e877 100644 --- a/src/thread/mtx_timedlock.c +++ b/src/thread/mtx_timedlock_monotonic.c @@ -1,13 +1,13 @@ -#include -#include -#include - -int mtx_timedlock(mtx_t *restrict m, const struct timespec *restrict ts) -{ - int ret =3D __pthread_mutex_timedlock((pthread_mutex_t *)m, ts); - switch (ret) { - default: return thrd_error; - case 0: return thrd_success; - case ETIMEDOUT: return thrd_timedout; - } -} +#include =0D +#include =0D +#include =0D +=0D +int mtx_timedlock(mtx_t *restrict m, const struct timespec *restrict ts)=0D +{=0D + int ret =3D pthread_mutex_clocklock((pthread_mutex_t *)m, CLOCK_MONOTONIC= , ts);=0D + switch (ret) {=0D + default: return thrd_error;=0D + case 0: return thrd_success;=0D + case ETIMEDOUT: return thrd_timedout;=0D + }=0D +}=0D --=20 2.39.0.windows.1