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 3618 invoked from network); 20 Jun 2023 14:38:04 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 20 Jun 2023 14:38:04 -0000 Received: (qmail 20329 invoked by uid 550); 20 Jun 2023 14:37: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 20210 invoked from network); 20 Jun 2023 14:37:39 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687271848; x=1689863848; 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=XYLFZvyZpCXukjpqGewO/sLCQYoBq6zTrE5DUs/Sn2M=; b=e9WuWsB2dYpoMNuo/t8GiLVDMmujUCk64bHNjnwLxlccBFs4QDy9djfdjRftsAHusE PlPGIWTZKVKbN9vXjZrtSP+pKhbDMBVNSWqnN84Zmfv+x2ob49gPJKUBvMVJwEvlGdCK Yx6RptaVzCpJZAB060Cr/HTcDBBm3/CsHYF4HWX4nksXIKtNB1gbieIbi3fhnaNVsSwB txSkoXr9YVuJVNz2CKZkW6061FmuI7BLbetHgflmPPNEwvc8+AOj+oOOLzpTPne5xB9V /Kz5l8csPTA+nQsC+IYHn0nPrvilfLrvSUiaj7ZlJLQiW8PKIc7uOJX4Ij22MdQBGV3G DEPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687271848; x=1689863848; 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=XYLFZvyZpCXukjpqGewO/sLCQYoBq6zTrE5DUs/Sn2M=; b=McCMkb8qh8qjO5cnuB+dm4kVBa9Eobibw6IssZM6Hg1R5mQsZkMtFUrLNaImJXLcwG EHA6jhHdgD6R3VWriw9E/YNCw3OFU1Q23scwGs4EgRoOVFGNxiiWWSHnSo6q50Dm4gL4 jPzwKModeBEarVhlMOIYAuS6oDqxDWav/j3U5Kkufx6pzHVb3C+g7GeeIb+uxpJxaTEz S/ergc7sq54w6K8NQsV48mLsJxARU1vU4PccsfWyXKkFumjudqQRNAjBRdtQzqx8oMnC 57PI/YLVs8DHuWLPEK4IhbKhmecVBP9aVy8443QVT2hhkRQt6of3p+81qJ9k7aUPVzK5 LimQ== X-Gm-Message-State: AC+VfDyznSVQVdmcbCvo/GjmsG+yICcFftWCuL5DL2S3aB5KEJcoU7Xe hl1HupErQ2G3mtQNJ7ipMwE= X-Google-Smtp-Source: ACHHUZ4/hQE05sv3IgFR8JvM4abIV89DRHldwH1L60x73Cr00fzOpBBoSQqNQRwXY14+Qlyg64l7Xg== X-Received: by 2002:a05:6808:120c:b0:3a0:3f7f:2329 with SMTP id a12-20020a056808120c00b003a03f7f2329mr1331041oil.54.1687271848167; Tue, 20 Jun 2023 07:37:28 -0700 (PDT) From: Yonggang Luo To: Jens Gustedt , enh , musl@lists.openwall.com Cc: Yonggang Luo Date: Tue, 20 Jun 2023 22:37:01 +0800 Message-Id: <20230620143703.1415-4-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 3/5] 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 | 8 ++++---- src/thread/pthread_cond_timedwait.c | 9 +++++++++ src/thread/pthread_mutex_clocklock.c | 12 ++++++------ src/thread/pthread_mutex_timedlock.c | 8 ++++++++ 9 files changed, 53 insertions(+), 10 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_timedwait.c create mode 100644 src/thread/pthread_mutex_timedlock.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..615473b1 --- /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_clockwait(c, m, clock, !ts32 ? 0 : (&(struct timespec= ){=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..1267f255 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_clockwait_time32() __asm__("pthread_cond_clockwait"); 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..7fb2d162 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_clockwait(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_clockwait, __pthread_cond_clockwait_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..d7fe7974 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_clockwait(pthread_cond_t *restrict, pthread_mute= x_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 index c5b35a6c..4d178c27 100644 --- a/src/thread/pthread_cond_clockwait.c +++ b/src/thread/pthread_cond_clockwait.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_clockwait(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,4 @@ int __private_cond_signal(pthread_cond_t *c, int n) return 0; } =20 -weak_alias(__pthread_cond_timedwait, pthread_cond_timedwait); +weak_alias(__pthread_cond_clockwait, pthread_cond_clockwait); diff --git a/src/thread/pthread_cond_timedwait.c b/src/thread/pthread_cond_= timedwait.c new file mode 100644 index 00000000..da803df7 --- /dev/null +++ b/src/thread/pthread_cond_timedwait.c @@ -0,0 +1,9 @@ +#include "pthread_impl.h" + +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_clockwait(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 index 87f89287..4a0a945f 100644 --- a/src/thread/pthread_mutex_clocklock.c +++ b/src/thread/pthread_mutex_clocklock.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, clockid= _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, clockid_t clk, = const struct timespec *restrict at) { if ((m->_m_type&15) =3D=3D PTHREAD_MUTEX_NORMAL && !a_cas(&m->_m_lock, 0, EBUSY)) @@ -65,7 +65,7 @@ int __pthread_mutex_timedlock(pthread_mutex_t *restrict m= , const struct timespec r =3D __pthread_mutex_trylock(m); if (r !=3D EBUSY) return r; =20 - if (type&8) return pthread_mutex_timedlock_pi(m, at); + if (type&8) return pthread_mutex_timedlock_pi(m, clk, at); =20 int spins =3D 100; while (spins-- && m->_m_lock && !m->_m_waiters) a_spin(); @@ -82,11 +82,11 @@ 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 -weak_alias(__pthread_mutex_timedlock, pthread_mutex_timedlock); +weak_alias(__pthread_mutex_clocklock, pthread_mutex_clocklock); diff --git a/src/thread/pthread_mutex_timedlock.c b/src/thread/pthread_mute= x_timedlock.c new file mode 100644 index 00000000..14a87065 --- /dev/null +++ b/src/thread/pthread_mutex_timedlock.c @@ -0,0 +1,8 @@ +#include "pthread_impl.h" + +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