git: bf2939ea6087 - main - pthread_mutex_timedlock(3): return EDEADLK on detected recursion attempt
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 10 Nov 2026 00:22:09 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=bf2939ea60872d7791987d1727798e90eb904279
commit bf2939ea60872d7791987d1727798e90eb904279
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-11-05 22:01:18 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-10 00:21:18 +0000
pthread_mutex_timedlock(3): return EDEADLK on detected recursion attempt
for ERRORCHECK and ADAPTIVE_NP mutexes, instead of ETIMEDOUT. This is
explicitly specified by POSIX.
Reviewed by: markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D61253
---
lib/libthr/thread/thr_mutex.c | 22 +++++-----------------
share/man/man3/pthread_mutex_timedlock.3 | 2 +-
2 files changed, 6 insertions(+), 18 deletions(-)
diff --git a/lib/libthr/thread/thr_mutex.c b/lib/libthr/thread/thr_mutex.c
index 58c79c973a9b..f257a6868360 100644
--- a/lib/libthr/thread/thr_mutex.c
+++ b/lib/libthr/thread/thr_mutex.c
@@ -899,23 +899,11 @@ mutex_self_lock(struct pthread_mutex *m, const struct timespec *abstime)
switch (PMUTEX_TYPE(m->m_flags)) {
case PTHREAD_MUTEX_ERRORCHECK:
case PTHREAD_MUTEX_ADAPTIVE_NP:
- if (abstime) {
- if (abstime->tv_sec < 0 || abstime->tv_nsec < 0 ||
- abstime->tv_nsec >= 1000000000) {
- ret = EINVAL;
- } else {
- clock_gettime(CLOCK_REALTIME, &ts1);
- TIMESPEC_SUB(&ts2, abstime, &ts1);
- __sys_nanosleep(&ts2, NULL);
- ret = ETIMEDOUT;
- }
- } else {
- /*
- * POSIX specifies that mutexes should return
- * EDEADLK if a recursive lock is detected.
- */
- ret = EDEADLK;
- }
+ /*
+ * POSIX specifies that mutexes should return EDEADLK
+ * if a recursive lock is detected.
+ */
+ ret = EDEADLK;
break;
case PTHREAD_MUTEX_NORMAL:
diff --git a/share/man/man3/pthread_mutex_timedlock.3 b/share/man/man3/pthread_mutex_timedlock.3
index b6e95edbe46e..793f975e286e 100644
--- a/share/man/man3/pthread_mutex_timedlock.3
+++ b/share/man/man3/pthread_mutex_timedlock.3
@@ -85,7 +85,7 @@ maximum number of recursive locks for the
.Fa mutex
has been exceeded.
.It Bq Er EDEADLK
-The current thread already owns the
+The current thread already owns the error-checking
.Fa mutex .
.It Bq Er EOWNERDEAD
The argument