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 4377 invoked from network); 20 Jun 2023 00:25:55 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 20 Jun 2023 00:25:55 -0000 Received: (qmail 6086 invoked by uid 550); 20 Jun 2023 00:25:40 -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 5965 invoked from network); 20 Jun 2023 00:25:39 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687220727; x=1689812727; 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=SCHTqiZU6FQ/DAIyy3sqSVVHhRyv2BFKanEN+8Vxd/k=; b=kwx4iQmmudgigI3/sfmiXX8P5oCcjzDLFLnYLr5Wt2qZtpqrcdTALOpDGYhxOCn+la VuX9T23HkXcEAtU4CTHQMvRbJG9Y0eCF5ObWbRFsfkiLXUiWLMGU6/3v2sIsHAQJx+Da RAeig5wLETWfi6vxcG6NZZlaZh1iubgSOJhTali7T1oT1h+UixNhtBBgpJb1QPbmQDoW SltKOfwxasx23DaJeuu4gc6WEIdxu1xuMTGQrnqlYtXed51rK/ZGuWCBH4B00EFA7UKd rqwlFo+chKjlgC1eFG0wOsFczxTRoCVgwN1ezTNZ0QLskO6beLXp7TlVUoGXZ7glyDmA /+MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687220727; x=1689812727; 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=SCHTqiZU6FQ/DAIyy3sqSVVHhRyv2BFKanEN+8Vxd/k=; b=SBONei5jREtqRv8F10hjkEyxVUg//28/RAaOwPyBcw3+r+ZsBUan9lIphQr8eNS7GB pXbeMFd6fBXaFESG1JUmh45qdvO3fxgsye3HkpWtXp0AIXCrqLgR0A3VtbMCB5wv8btP 1l5db89FW6FqgwPWuh/gdrS9o8J7GXeIFyoi0TTpJJmqM4vV5avcfPP9uoOHgQ/7VZDt 60gVKAGbdEEWvnSadSZn/byD1VACy4yz0pQQx112mGVFpK7N7q/9AQJ0um93W8BBqt6y 0Pi0g8nVwsqAh1d5Z79EdF6yzlxfA2QZQnNDaBjuh8O1NxSrLmXiWHf9WMzF6+S4CJP6 MnNQ== X-Gm-Message-State: AC+VfDz+6O40iq5bTxNTQZRSocBFRq/lCRzDSBOjlrJHveuStrW/c5LR NzwlD4SXyHWqoYTcfkg6wqI= X-Google-Smtp-Source: ACHHUZ42eLK29jlggJWwzqNOVoVEzQoM0v41jNkXI9K9rwSQIdTPwhGzgFPuEpD3A/MrrHcKjoVJWw== X-Received: by 2002:a17:903:2349:b0:1b3:ec39:f438 with SMTP id c9-20020a170903234900b001b3ec39f438mr24347240plh.32.1687220726678; Mon, 19 Jun 2023 17:25:26 -0700 (PDT) From: Yonggang Luo To: Jens Gustedt , musl@lists.openwall.com Cc: Yonggang Luo Date: Tue, 20 Jun 2023 08:25:05 +0800 Message-Id: <20230620002507.796-3-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 2/4] add pthread_mutex_clocklock and pthread_cond_clockdwait These two functions are already implemented in glibc, android bionic libc, = qnx libc Signed-off-by: Yonggang Luo --- compat/time32/pthread_cond_clockwait_time32.c | 9 +++++++++ compat/time32/pthread_mutex_clocklock_time32.c | 9 +++++++++ compat/time32/time32.h | 2 ++ include/pthread.h | 4 ++++ src/include/pthread.h | 2 ++ src/thread/pthread_cond_clockwait.c | 3 +++ src/thread/pthread_cond_timedwait.c | 12 +++++++++--- src/thread/pthread_mutex_clocklock.c | 3 +++ src/thread/pthread_mutex_timedlock.c | 13 +++++++++---- 9 files changed, 50 insertions(+), 7 deletions(-) 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/pthread_cond_clockwait.c create mode 100644 src/thread/pthread_mutex_clocklock.c diff --git a/compat/time32/pthread_cond_clockwait_time32.c b/compat/time32/= pthread_cond_clockwait_time32.c new file mode 100644 index 00000000..1a18114f --- /dev/null +++ b/compat/time32/pthread_cond_clockwait_time32.c @@ -0,0 +1,9 @@ +#include "time32.h"=0D +#include =0D +#include =0D +=0D +int __pthread_cond_clockwait_time32(pthread_cond_t *restrict c, pthread_mu= tex_t *restrict m, clockid_t clock, const struct timespec32 *restrict ts32)= =0D +{=0D + return pthread_cond_clockdwait(c, m, clock, !ts32 ? 0 : (&(struct timespe= c){=0D + .tv_sec =3D ts32->tv_sec, .tv_nsec =3D ts32->tv_nsec}));=0D +}=0D diff --git a/compat/time32/pthread_mutex_clocklock_time32.c b/compat/time32= /pthread_mutex_clocklock_time32.c new file mode 100644 index 00000000..d54e85a7 --- /dev/null +++ b/compat/time32/pthread_mutex_clocklock_time32.c @@ -0,0 +1,9 @@ +#include "time32.h" +#include +#include + +int __pthread_mutex_clocklock_time32(pthread_mutex_t *restrict m, clockid_= t clk, const struct timespec32 *restrict ts32) +{ + return pthread_mutex_clocklock(m, clk, !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 fdec17c3..e0af9bff 100644 --- a/compat/time32/time32.h +++ b/compat/time32/time32.h @@ -59,7 +59,9 @@ int __mtx_timedlock_time32() __asm__("mtx_timedlock"); int __nanosleep_time32() __asm__("nanosleep"); int __ppoll_time32() __asm__("ppoll"); int __pselect_time32() __asm__("pselect"); +int __pthread_cond_clockdwait_time32() __asm__("pthread_cond_clockdwait"); int __pthread_cond_timedwait_time32() __asm__("pthread_cond_timedwait"); +int __pthread_mutex_clocklock_time32() __asm__("pthread_mutex_clocklock"); int __pthread_mutex_timedlock_time32() __asm__("pthread_mutex_timedlock"); int __pthread_rwlock_timedrdlock_time32() __asm__("pthread_rwlock_timedrdl= ock"); int __pthread_rwlock_timedwrlock_time32() __asm__("pthread_rwlock_timedwrl= ock"); diff --git a/include/pthread.h b/include/pthread.h index 89fd9ff7..4062ff9b 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -107,6 +107,7 @@ int pthread_mutex_init(pthread_mutex_t *__restrict, con= st pthread_mutexattr_t *_ int pthread_mutex_lock(pthread_mutex_t *); int pthread_mutex_unlock(pthread_mutex_t *); int pthread_mutex_trylock(pthread_mutex_t *); +int pthread_mutex_clocklock(pthread_mutex_t *__restrict, clockid_t, const = struct timespec *__restrict); int pthread_mutex_timedlock(pthread_mutex_t *__restrict, const struct time= spec *__restrict); int pthread_mutex_destroy(pthread_mutex_t *); int pthread_mutex_consistent(pthread_mutex_t *); @@ -117,6 +118,7 @@ int pthread_mutex_setprioceiling(pthread_mutex_t *__res= trict, int, int *__restri int pthread_cond_init(pthread_cond_t *__restrict, const pthread_condattr_t= *__restrict); int pthread_cond_destroy(pthread_cond_t *); int pthread_cond_wait(pthread_cond_t *__restrict, pthread_mutex_t *__restr= ict); +int pthread_cond_clockdwait(pthread_cond_t *__restrict, pthread_mutex_t *_= _restrict, clockid_t, const struct timespec *__restrict); int pthread_cond_timedwait(pthread_cond_t *__restrict, pthread_mutex_t *__= restrict, const struct timespec *__restrict); int pthread_cond_broadcast(pthread_cond_t *); int pthread_cond_signal(pthread_cond_t *); @@ -229,7 +231,9 @@ int pthread_timedjoin_np(pthread_t, void **, const stru= ct timespec *); #endif =20 #if _REDIR_TIME64 +__REDIR(pthread_mutex_clocklock, __pthread_mutex_clocklock_time64); __REDIR(pthread_mutex_timedlock, __pthread_mutex_timedlock_time64); +__REDIR(pthread_cond_clockdwait, __pthread_cond_clockdwait_time64); __REDIR(pthread_cond_timedwait, __pthread_cond_timedwait_time64); __REDIR(pthread_rwlock_timedrdlock, __pthread_rwlock_timedrdlock_time64); __REDIR(pthread_rwlock_timedwrlock, __pthread_rwlock_timedwrlock_time64); diff --git a/src/include/pthread.h b/src/include/pthread.h index 7167d3e1..ec533264 100644 --- a/src/include/pthread.h +++ b/src/include/pthread.h @@ -12,9 +12,11 @@ hidden int __pthread_join(pthread_t, void **); hidden int __pthread_mutex_lock(pthread_mutex_t *); hidden int __pthread_mutex_trylock(pthread_mutex_t *); hidden int __pthread_mutex_trylock_owner(pthread_mutex_t *); +hidden int __pthread_mutex_clocklock(pthread_mutex_t *restrict, clockid_t,= const struct timespec *restrict); hidden int __pthread_mutex_timedlock(pthread_mutex_t *restrict, const stru= ct timespec *restrict); hidden int __pthread_mutex_unlock(pthread_mutex_t *); hidden int __private_cond_signal(pthread_cond_t *, int); +hidden int __pthread_cond_clockdwait(pthread_cond_t *restrict, pthread_mut= ex_t *restrict, clockid_t, const struct timespec *restrict); hidden int __pthread_cond_timedwait(pthread_cond_t *restrict, pthread_mute= x_t *restrict, const struct timespec *restrict); hidden int __pthread_key_create(pthread_key_t *, void (*)(void *)); hidden int __pthread_key_delete(pthread_key_t); diff --git a/src/thread/pthread_cond_clockwait.c b/src/thread/pthread_cond_= clockwait.c new file mode 100644 index 00000000..1273f06d --- /dev/null +++ b/src/thread/pthread_cond_clockwait.c @@ -0,0 +1,3 @@ +#include "pthread_impl.h"=0D +=0D +weak_alias(__pthread_cond_clockdwait, pthread_cond_clockdwait);=0D diff --git a/src/thread/pthread_cond_timedwait.c b/src/thread/pthread_cond_= timedwait.c index c5b35a6c..61df6673 100644 --- a/src/thread/pthread_cond_timedwait.c +++ b/src/thread/pthread_cond_timedwait.c @@ -59,10 +59,10 @@ enum { LEAVING, }; =20 -int __pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *= restrict m, const struct timespec *restrict ts) +int __pthread_cond_clockdwait(pthread_cond_t *restrict c, pthread_mutex_t = *restrict m, clockid_t clk, const struct timespec *restrict ts) { struct waiter node =3D { 0 }; - int e, seq, clock =3D c->_c_clock, cs, shared=3D0, oldstate, tmp; + int e, seq, cs, shared=3D0, oldstate, tmp; volatile int *fut; =20 if ((m->_m_type&15) && (m->_m_lock&INT_MAX) !=3D __pthread_self()->tid) @@ -97,7 +97,7 @@ int __pthread_cond_timedwait(pthread_cond_t *restrict c, = pthread_mutex_t *restri __pthread_setcancelstate(PTHREAD_CANCEL_MASKED, &cs); if (cs =3D=3D PTHREAD_CANCEL_DISABLE) __pthread_setcancelstate(cs, 0); =20 - do e =3D __timedwait_cp(fut, seq, clock, ts, !shared); + do e =3D __timedwait_cp(fut, seq, clk, ts, !shared); while (*fut=3D=3Dseq && (!e || e=3D=3DEINTR)); if (e =3D=3D EINTR) e =3D 0; =20 @@ -210,4 +210,10 @@ int __private_cond_signal(pthread_cond_t *c, int n) return 0; } =20 +int __pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *= restrict m, const struct timespec *restrict ts) +{ + int clock =3D c->_c_clock; + return __pthread_cond_clockdwait(c, m, clock, ts); +} + weak_alias(__pthread_cond_timedwait, pthread_cond_timedwait); diff --git a/src/thread/pthread_mutex_clocklock.c b/src/thread/pthread_mute= x_clocklock.c new file mode 100644 index 00000000..2b869f4f --- /dev/null +++ b/src/thread/pthread_mutex_clocklock.c @@ -0,0 +1,3 @@ +#include "pthread_impl.h"=0D +=0D +weak_alias(__pthread_mutex_clocklock, pthread_mutex_clocklock);=0D diff --git a/src/thread/pthread_mutex_timedlock.c b/src/thread/pthread_mute= x_timedlock.c index 87f89287..f9c8fc56 100644 --- a/src/thread/pthread_mutex_timedlock.c +++ b/src/thread/pthread_mutex_timedlock.c @@ -18,7 +18,7 @@ static int __futex4(volatile void *addr, int op, int val,= const struct timespec return __syscall(SYS_futex, addr, op, val, to); } =20 -static int pthread_mutex_timedlock_pi(pthread_mutex_t *restrict m, const s= truct timespec *restrict at) +static int pthread_mutex_timedlock_pi(pthread_mutex_t *restrict m, clock_i= d_t clk, const struct timespec *restrict at) { int type =3D m->_m_type; int priv =3D (type & 128) ^ 128; @@ -48,12 +48,12 @@ static int pthread_mutex_timedlock_pi(pthread_mutex_t *= restrict m, const struct case EDEADLK: if ((type&3) =3D=3D PTHREAD_MUTEX_ERRORCHECK) return e; } - do e =3D __timedwait(&(int){0}, 0, CLOCK_REALTIME, at, 1); + do e =3D __timedwait(&(int){0}, 0, clk, at, 1); while (e !=3D ETIMEDOUT); return e; } =20 -int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct ti= mespec *restrict at) +int __pthread_mutex_clocklock(pthread_mutex_t *restrict m, clock_id_t clk,= const struct timespec *restrict at) { if ((m->_m_type&15) =3D=3D PTHREAD_MUTEX_NORMAL && !a_cas(&m->_m_lock, 0, EBUSY)) @@ -82,11 +82,16 @@ int __pthread_mutex_timedlock(pthread_mutex_t *restrict= m, const struct timespec a_inc(&m->_m_waiters); t =3D r | 0x80000000; a_cas(&m->_m_lock, r, t); - r =3D __timedwait(&m->_m_lock, t, CLOCK_REALTIME, at, priv); + r =3D __timedwait(&m->_m_lock, t, clk, at, priv); a_dec(&m->_m_waiters); if (r && r !=3D EINTR) break; } return r; } =20 +int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct ti= mespec *restrict at) +{ + return __pthread_mutex_clocklock(m, CLOCK_REALTIME, at); +} + weak_alias(__pthread_mutex_timedlock, pthread_mutex_timedlock); --=20 2.39.0.windows.1