From nobody Tue Nov 17 01:09:48 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jT68X3yZhz71Q2H for ; Tue, 17 Nov 2026 01:09:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jT68X0QrZz3CWd for ; Tue, 17 Nov 2026 01:09:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794877788; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iSnoePKjZh20bJR2aiyweF64MkKtmHX6707/SM7vc5Q=; b=YXjnmOuNHn6nm7KoSPxFsX9mu7JKwjZQkfR0LjpT8uPig+FQFvfLOGf+0jn58tKnOLwmDx LIFShlPFvrEd6GJ8V/dHj0lZw76UpllEvGoJSj9H9SHOANeeJTiPrdG5TrBl2hdiLysRyg jVtird1OZaKRH/8FmOEa3hr3pJVsVd4eP+t8lfjkE41MNb1WtXQomUh4sS+zr64WpVvUCT ZrikmvWl7xZ8NtapBz06f4hts/oCTN2xLA6BLCIPodh/aSVEdn8VM3hZtWqkVUawhrJIC1 zJjoTerSYA1nIaZcLHeog2cx7puImHacWLVAqNvS1e2FDA/jSCg4uhqShkXQ/A== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794877788; b=Xjn1zywv0BCoA1boDXPiM8edKoS3l3CzCcDAIUFkNtO6nvKsDlRiYQyxc0ZvEWEraJSdGc mjLbjbOlC3Fry/u8NJzpgsTj1n3H7JVSZ4eSBR5/zhs6hqhq/0lh4IRASY973lfSLcByR/ EvjYYU9PXKxNvGTiP5L4k/abxVpLUmurjZm7FZNEc8hulQjUfVbxep0kw6csXoh4BpEY53 hsCfe9jHh9sATmJjEsIVAmWulBOXRzeqrqY+rN8dku6tteIxmiZJvJLpjf1qp/XaUZqVUS YJYJnZd0Ttqj3MPo93xCqLpDv8t8E9NYQAgE/rujjv3wXwORIOSnGDtLSPFkZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794877788; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iSnoePKjZh20bJR2aiyweF64MkKtmHX6707/SM7vc5Q=; b=XUJjVYHXGox2S5/vGIo701lgGYJCE717cZ5V/LQvsePhZAdwZAGGxsaEuedIrlB4VcAx7e vshq0ZLBPA1DHRFJ7fLBI66pUG7Gw60E0QQb6nkjDrepc2XFhEgQ8DgY/2JiyT+RGfiMcN qBFfAW7JKiLgciVBCwKC3bMp5nhhggHinEicOw+/5IYyg/IhO7tpWCZRJBepNkjW0KH/Ti gexeSAnkuZgm6DyXPT1ZAu1qjI+FRV+Lxv7cYHaIqyBXrdAcbixp6Tll6kSy0WCYdc7Jkh A0+bKLyr0dj8sneNxjsEv1zraDSZtJUBM29T2B84fP2MPSPK9JpjPXMfGkhZ/w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jT68X05ybzJF4 for ; Tue, 17 Nov 2026 01:09:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1f070 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 01:09:48 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 4655558c6c2d - stable/15 - libthr: add pthread_mutex_clocklock(3) List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 4655558c6c2d24ccf656685f4b507c24a97a0736 Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 01:09:48 +0000 Message-Id: <6afba95c.1f070.2b404762@gitrepo.freebsd.org> The branch stable/15 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=4655558c6c2d24ccf656685f4b507c24a97a0736 commit 4655558c6c2d24ccf656685f4b507c24a97a0736 Author: Konstantin Belousov AuthorDate: 2026-11-05 17:23:49 +0000 Commit: Konstantin Belousov CommitDate: 2026-11-17 00:25:02 +0000 libthr: add pthread_mutex_clocklock(3) (cherry picked from commit b7c2db4c772ba3c61f4760eca011332c9c12da1c) --- include/pthread.h | 5 +++++ lib/libthr/pthread.map | 1 + lib/libthr/thread/thr_mutex.c | 42 ++++++++++++++++++++++++++++-------------- lib/libthr/thread/thr_umtx.c | 6 +++--- lib/libthr/thread/thr_umtx.h | 4 ++-- 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/include/pthread.h b/include/pthread.h index 1686b54314ef..9ff9748e699f 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -235,6 +235,11 @@ int pthread_mutexattr_gettype( const pthread_mutexattr_t * __restrict, int * __restrict); int pthread_mutexattr_settype(pthread_mutexattr_t *, int); int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int); +#if __POSIX_VISIBLE >= 202405 +int pthread_mutex_clocklock(pthread_mutex_t * __restrict __mutex, + clockid_t, const struct timespec * __restrict) + __trylocks_exclusive(0, *__mutex); +#endif int pthread_mutex_consistent(pthread_mutex_t * __mutex) __requires_exclusive(*__mutex); int pthread_mutex_destroy(pthread_mutex_t * __mutex) diff --git a/lib/libthr/pthread.map b/lib/libthr/pthread.map index 80a07d472a0e..214a7c8b4234 100644 --- a/lib/libthr/pthread.map +++ b/lib/libthr/pthread.map @@ -345,6 +345,7 @@ FBSD_1.8 { FBSD_1.9 { pthread_cond_clockwait; + pthread_mutex_clocklock; pthread_query_np; pthread_query_all_np; pthread_tryjoin_np; diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c index e1e790aa43bf..a81f36d35135 100644 --- a/lib/libthr/thread/thr_mutex.c +++ b/lib/libthr/thread/thr_mutex.c @@ -64,6 +64,8 @@ _Static_assert(sizeof(struct pthread_mutex) <= THR_PAGE_SIZE_MIN, */ int __pthread_mutex_timedlock(pthread_mutex_t * __restrict mutex, const struct timespec * __restrict abstime); +int __pthread_mutex_clocklock(pthread_mutex_t * __restrict mutex, + clockid_t clock, const struct timespec * __restrict abstime); int _pthread_mutex_getspinloops_np(pthread_mutex_t *mutex, int *count); int _pthread_mutex_setspinloops_np(pthread_mutex_t *mutex, int count); int __pthread_mutex_setspinloops_np(pthread_mutex_t *mutex, int count); @@ -73,10 +75,10 @@ int __pthread_mutex_setyieldloops_np(pthread_mutex_t *mutex, int count); static int mutex_self_trylock(pthread_mutex_t); static int mutex_self_lock(pthread_mutex_t, - const struct timespec *abstime); + const struct timespec *abstime, clockid_t clockid); static int mutex_unlock_common(struct pthread_mutex *, bool, int *); static int mutex_lock_sleep(struct pthread *, pthread_mutex_t, - const struct timespec *); + const struct timespec *, clockid_t clockid); static void mutex_init_robust(struct pthread *curthread); static int mutex_qidx(struct pthread_mutex *m); static bool is_robust_mutex(struct pthread_mutex *m); @@ -90,6 +92,7 @@ __weak_reference(__Tthr_mutex_lock, __pthread_mutex_lock); __strong_reference(__Tthr_mutex_lock, _pthread_mutex_lock); __weak_reference(__pthread_mutex_timedlock, pthread_mutex_timedlock); __strong_reference(__pthread_mutex_timedlock, _pthread_mutex_timedlock); +__weak_reference(__pthread_mutex_clocklock, pthread_mutex_clocklock); __weak_reference(__Tthr_mutex_trylock, pthread_mutex_trylock); __weak_reference(__Tthr_mutex_trylock, __pthread_mutex_trylock); __strong_reference(__Tthr_mutex_trylock, _pthread_mutex_trylock); @@ -654,14 +657,14 @@ __Tthr_mutex_trylock(pthread_mutex_t *mutex) static int mutex_lock_sleep(struct pthread *curthread, struct pthread_mutex *m, - const struct timespec *abstime) + const struct timespec *abstime, clockid_t clockid) { uint32_t id, owner; int count, ret; id = TID(curthread); if (PMUTEX_OWNER_ID(m) == id) - return (mutex_self_lock(m, abstime)); + return (mutex_self_lock(m, abstime, clockid)); /* * For adaptive mutexes, spin for a bit in the expectation @@ -707,10 +710,11 @@ sleep_in_kernel: if (abstime == NULL) ret = __thr_umutex_lock(&m->m_lock, id); else if (__predict_false(abstime->tv_nsec < 0 || - abstime->tv_nsec >= 1000000000)) + abstime->tv_nsec >= 1000000000) || + _thr_check_clockid(clockid) != 0) ret = EINVAL; else - ret = __thr_umutex_timedlock(&m->m_lock, id, abstime); + ret = __thr_umutex_timedlock(&m->m_lock, id, abstime, clockid); done: if (ret == 0 || ret == EOWNERDEAD) { enqueue_mutex(curthread, m, ret); @@ -722,7 +726,7 @@ done: static __always_inline int mutex_lock_common(struct pthread_mutex *m, const struct timespec *abstime, - bool cvattach, bool rb_onlist) + clockid_t clockid, bool cvattach, bool rb_onlist) { struct pthread *curthread; int ret, robust; @@ -739,7 +743,7 @@ mutex_lock_common(struct pthread_mutex *m, const struct timespec *abstime, if (ret == EOWNERDEAD) m->m_lock.m_flags |= UMUTEX_NONCONSISTENT; } else { - ret = mutex_lock_sleep(curthread, m, abstime); + ret = mutex_lock_sleep(curthread, m, abstime, clockid); } if (!rb_onlist && robust) _mutex_leave_robust(curthread, m); @@ -758,12 +762,12 @@ __Tthr_mutex_lock(pthread_mutex_t *mutex) _thr_check_init(); ret = check_and_init_mutex(mutex, &m); if (ret == 0) - ret = mutex_lock_common(m, NULL, false, false); + ret = mutex_lock_common(m, NULL, CLOCK_REALTIME, false, false); return (ret); } int -__pthread_mutex_timedlock(pthread_mutex_t * __restrict mutex, +__pthread_mutex_clocklock(pthread_mutex_t * __restrict mutex, clockid_t clockid, const struct timespec * __restrict abstime) { struct pthread_mutex *m; @@ -772,10 +776,17 @@ __pthread_mutex_timedlock(pthread_mutex_t * __restrict mutex, _thr_check_init(); ret = check_and_init_mutex(mutex, &m); if (ret == 0) - ret = mutex_lock_common(m, abstime, false, false); + ret = mutex_lock_common(m, abstime, clockid, false, false); return (ret); } +int +__pthread_mutex_timedlock(pthread_mutex_t * __restrict mutex, + const struct timespec * __restrict abstime) +{ + return (__pthread_mutex_clocklock(mutex, CLOCK_REALTIME, abstime)); +} + int _thr_mutex_unlock(pthread_mutex_t *mutex) { @@ -797,7 +808,7 @@ _mutex_cv_lock(struct pthread_mutex *m, int count, bool rb_onlist) { int error; - error = mutex_lock_common(m, NULL, true, rb_onlist); + error = mutex_lock_common(m, NULL, CLOCK_REALTIME, true, rb_onlist); if (error == 0 || error == EOWNERDEAD) m->m_count = count; return (error); @@ -889,7 +900,8 @@ mutex_self_trylock(struct pthread_mutex *m) } static int -mutex_self_lock(struct pthread_mutex *m, const struct timespec *abstime) +mutex_self_lock(struct pthread_mutex *m, const struct timespec *abstime, + clockid_t clockid) { struct timespec ts1, ts2; int ret; @@ -914,8 +926,10 @@ mutex_self_lock(struct pthread_mutex *m, const struct timespec *abstime) if (abstime->tv_sec < 0 || abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) { ret = EINVAL; + } else if (_thr_check_clockid(clockid) != 0 || + clock_gettime(clockid, &ts1) == -1) { + ret = EINVAL; } else { - clock_gettime(CLOCK_REALTIME, &ts1); TIMESPEC_SUB(&ts2, abstime, &ts1); __sys_nanosleep(&ts2, NULL); ret = ETIMEDOUT; diff --git a/lib/libthr/thread/thr_umtx.c b/lib/libthr/thread/thr_umtx.c index edd0dacdaff1..410e9c181235 100644 --- a/lib/libthr/thread/thr_umtx.c +++ b/lib/libthr/thread/thr_umtx.c @@ -108,7 +108,7 @@ __thr_umutex_lock_spin(struct umutex *mtx, uint32_t id) int __thr_umutex_timedlock(struct umutex *mtx, uint32_t id, - const struct timespec *abstime) + const struct timespec *abstime, clockid_t clockid) { struct _umtx_time *tm_p, timeout; size_t tm_size; @@ -119,7 +119,7 @@ __thr_umutex_timedlock(struct umutex *mtx, uint32_t id, tm_p = NULL; tm_size = 0; } else { - timeout._clockid = CLOCK_REALTIME; + timeout._clockid = clockid; timeout._flags = UMTX_ABSTIME; timeout._timeout = *abstime; tm_p = &timeout; @@ -151,7 +151,7 @@ __thr_umutex_timedlock(struct umutex *mtx, uint32_t id, ret == ENOTRECOVERABLE) break; } - if (ret == ETIMEDOUT) + if (ret == ETIMEDOUT || ret == EINVAL) break; } return (ret); diff --git a/lib/libthr/thread/thr_umtx.h b/lib/libthr/thread/thr_umtx.h index eada8ab9297f..2ddc28af1df1 100644 --- a/lib/libthr/thread/thr_umtx.h +++ b/lib/libthr/thread/thr_umtx.h @@ -42,7 +42,7 @@ int __thr_umutex_lock(struct umutex *mtx, uint32_t id) __hidden; int __thr_umutex_lock_spin(struct umutex *mtx, uint32_t id) __hidden; int __thr_umutex_timedlock(struct umutex *mtx, uint32_t id, - const struct timespec *timeout) __hidden; + const struct timespec *timeout, clockid_t clockid) __hidden; int __thr_umutex_unlock(struct umutex *mtx) __hidden; int __thr_umutex_trylock(struct umutex *mtx) __hidden; int __thr_umutex_set_ceiling(struct umutex *mtx, uint32_t ceiling, @@ -145,7 +145,7 @@ _thr_umutex_timedlock(struct umutex *mtx, uint32_t id, if (_thr_umutex_trylock2(mtx, id) == 0) return (0); - return (__thr_umutex_timedlock(mtx, id, timeout)); + return (__thr_umutex_timedlock(mtx, id, timeout, CLOCK_REALTIME)); } static inline int