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 3666 invoked from network); 20 Jun 2023 14:38:25 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 20 Jun 2023 14:38:25 -0000 Received: (qmail 22000 invoked by uid 550); 20 Jun 2023 14:37:47 -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 21860 invoked from network); 20 Jun 2023 14:37:46 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687271854; x=1689863854; 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=ikeig8YjjA2/dcq94jS9c34vSyfzgEnGLXJb+npSkHw=; b=sjFSP014ttktXZndzuHHdsX5T9oWflxZap82v2DIZT38H3ypT1mTcsEUmILSGkuFpI PXwAkWYtOINDZK9MAZoQ+eKkHJpSzZm1LmO1vi+qVSHLDjTUMXegRlpEm6qx4Ih9GwYx GgAXnE1WB6nujF7vLE5Aoq5v9BjXQ2ovx7CzCPG1FSTdp5H0Cgy3svz+7HGuFqUWj65R 6kWgHY/C+qU2/yY8yjWK2//Vak8aTwMmN4VCodwQDRNgJvEhnbPzoUEOUYkYT3uKg8im P7IE3nDvFGvGj4pJGUYCM30LOyZDLcd95BzT7TTeiyl8KYg2laZscMmiIOxh059Tej4E a4WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687271854; x=1689863854; 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=ikeig8YjjA2/dcq94jS9c34vSyfzgEnGLXJb+npSkHw=; b=Hw4WVfcCKWuFzIwC2jSpKLGT87WhSEqjrmTsQcnp+XS4C9YLGgARxPmxnTaav7l+G2 vym4yJMhtEIikLoWrZ4kPlPkwqXvv+TS5MpBQalnhrqVvzYhfIvWMZa5ZzNwvvP/gNoU eA5bAr91O4eHupXyhknuNhDgFxLZmvKuOulB2uFZiS8tB65p0FifuwBv/9w3pderBwnn ABNV43RGsC2iCVsL7NV1TC20hBg2xIe/yfnaP51QeAkhqcWqpu3hlHv5RPfqm71CZy33 763IQ0Et+acur8pEM7WYXPgciDz/RodIVbC4RNxnP/IiypMn8T7PUWPYUncOGihjZeMa 0FSg== X-Gm-Message-State: AC+VfDzuMUQ96j0n2edPjhT6tMrOF8IoGy9VvB0k4oBhRcR3If3nhCQx 9xPkxzLHG/8g6YKTUu4ffGo= X-Google-Smtp-Source: ACHHUZ5h2ungVZ2u+aJZvaQAVDHe8avdQB5E7jN6Qcge/6jfe/VtIFcWJNkRm39T85ooox1KqQEliA== X-Received: by 2002:a17:90a:8a0b:b0:256:2cb7:406e with SMTP id w11-20020a17090a8a0b00b002562cb7406emr13220068pjn.45.1687271853809; Tue, 20 Jun 2023 07:37:33 -0700 (PDT) From: Yonggang Luo To: Jens Gustedt , enh , musl@lists.openwall.com Cc: Yonggang Luo Date: Tue, 20 Jun 2023 22:37:03 +0800 Message-Id: <20230620143703.1415-6-luoyonggang@gmail.com> X-Mailer: git-send-email 2.39.0.windows.1 In-Reply-To: <20230620143703.1415-1-luoyonggang@gmail.com> References: <20230620143703.1415-1-luoyonggang@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: [musl] [PATCH v3 5/5] c2y: Add monotonic timedlock/timedwait support for threads mtx/cnd Add two functions: mtx_timedlock_base cnd_timedwait_base That support for both TIME_UTC and TIME_MONOTONIC to achieve that Signed-off-by: Yonggang Luo --- compat/time32/cnd_timedwait_base_time32.c | 9 ++++++++ compat/time32/mtx_timedlock_base_time32.c | 9 ++++++++ compat/time32/time32.h | 2 ++ include/threads.h | 4 ++++ 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 ++++++++++++++++++++++ 8 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 compat/time32/cnd_timedwait_base_time32.c create mode 100644 compat/time32/mtx_timedlock_base_time32.c create mode 100644 src/thread/cnd_timedwait_base.c create mode 100644 src/thread/mtx_timedlock_base.c diff --git a/compat/time32/cnd_timedwait_base_time32.c b/compat/time32/cnd_= timedwait_base_time32.c new file mode 100644 index 00000000..433f9841 --- /dev/null +++ b/compat/time32/cnd_timedwait_base_time32.c @@ -0,0 +1,9 @@ +#include "time32.h" +#include +#include + +int __cnd_timedwait_base_time32(cnd_t *restrict c, mtx_t *restrict m, int = time_base, const struct timespec32 *restrict ts32) +{ + return cnd_timedwait_base(c, m, time_base, ts32 ? (&(struct timespec){ + .tv_sec =3D ts32->tv_sec, .tv_nsec =3D ts32->tv_nsec}) : 0); +} diff --git a/compat/time32/mtx_timedlock_base_time32.c b/compat/time32/mtx_= timedlock_base_time32.c new file mode 100644 index 00000000..8c3f27a1 --- /dev/null +++ b/compat/time32/mtx_timedlock_base_time32.c @@ -0,0 +1,9 @@ +#include "time32.h" +#include +#include + +int __mtx_timedlock_base_time32(mtx_t *restrict m, int time_base, const st= ruct timespec32 *restrict ts32) +{ + return mtx_timedlock_base(m, time_base, !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 1267f255..45ee6205 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_base_time32() __asm__("cnd_timedwait_base"); 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_base_time32() __asm__("mtx_timedlock_base"); 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..2c5f24f8 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_base(mtx_t *__restrict, int, 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_base(cnd_t *__restrict, mtx_t *__restrict, int, 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_base, __mtx_timedlock_base_time64); __REDIR(cnd_timedwait, __cnd_timedwait_time64); +__REDIR(cnd_timedwait_base, __cnd_timedwait_base_time64); #endif =20 #ifdef __cplusplus diff --git a/src/thread/cnd_timedwait.c b/src/thread/cnd_timedwait.c index 2802af52..60839fa0 100644 --- a/src/thread/cnd_timedwait.c +++ b/src/thread/cnd_timedwait.c @@ -4,11 +4,5 @@ =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); - switch (ret) { - /* May also return EINVAL or EPERM. */ - default: return thrd_error; - case 0: return thrd_success; - case ETIMEDOUT: return thrd_timedout; - } + return cnd_timedwait_base(c, m, TIME_UTC, ts); } diff --git a/src/thread/cnd_timedwait_base.c b/src/thread/cnd_timedwait_bas= e.c new file mode 100644 index 00000000..b0b37cac --- /dev/null +++ b/src/thread/cnd_timedwait_base.c @@ -0,0 +1,26 @@ +#include =0D +#include =0D +#include =0D +=0D +int cnd_timedwait_base(cnd_t *restrict c, mtx_t *restrict m, int time_base= , const struct timespec *restrict ts)=0D +{=0D + clockid_t clock =3D CLOCK_REALTIME;=0D + switch (time_base)=0D + {=0D + case TIME_UTC:=0D + clock =3D CLOCK_REALTIME;=0D + break;=0D + case TIME_MONOTONIC:=0D + clock =3D CLOCK_MONOTONIC;=0D + break;=0D + default:=0D + return thrd_error;=0D + }=0D + int ret =3D pthread_cond_clockwait((pthread_cond_t *)c, (pthread_mutex_t = *)m, clock, 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..49a28623 100644 --- a/src/thread/mtx_timedlock.c +++ b/src/thread/mtx_timedlock.c @@ -4,10 +4,5 @@ =20 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; - } + return mtx_timedlock_base(m, TIME_UTC, ts); } diff --git a/src/thread/mtx_timedlock_base.c b/src/thread/mtx_timedlock_bas= e.c new file mode 100644 index 00000000..3dda19ab --- /dev/null +++ b/src/thread/mtx_timedlock_base.c @@ -0,0 +1,25 @@ +#include =0D +#include =0D +#include =0D +=0D +int mtx_timedlock_base(mtx_t *restrict m, int time_base, const struct time= spec *restrict ts)=0D +{=0D + clockid_t clock =3D CLOCK_REALTIME;=0D + switch (time_base)=0D + {=0D + case TIME_UTC:=0D + clock =3D CLOCK_REALTIME;=0D + break;=0D + case TIME_MONOTONIC:=0D + clock =3D CLOCK_MONOTONIC;=0D + break;=0D + default:=0D + return thrd_error;=0D + }=0D + int ret =3D pthread_mutex_clocklock((pthread_mutex_t *)m, clock, 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