git: 894f70a2bd8c - main - libthr: drop use of try_gc in the end of thr_join
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 19 Oct 2026 05:23:26 UTC
The branch main has been updated by aokblast:
URL: https://cgit.FreeBSD.org/src/commit/?id=894f70a2bd8c7f67f131b76b9ce122a752818af3
commit 894f70a2bd8c7f67f131b76b9ce122a752818af3
Author: ShengYi Hung <aokblast@FreeBSD.org>
AuthorDate: 2026-10-13 22:40:05 +0000
Commit: ShengYi Hung <aokblast@FreeBSD.org>
CommitDate: 2026-10-19 05:23:14 +0000
libthr: drop use of try_gc in the end of thr_join
thr_try_gc unlock and lock again to make sure the lock order. However,
there is no reason for such roundtrip if the caller holds the correct
oder. As a result, we create a new helper function to add the thread
to gc list without unlock + lock and wire the join_common to this new helper.
Reviewed by: kib
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D60717
---
lib/libthr/thread/thr_join.c | 30 ++++++++++++++++++------------
1 file changed, 18 insertions(+), 12 deletions(-)
diff --git a/lib/libthr/thread/thr_join.c b/lib/libthr/thread/thr_join.c
index 16137d482632..bc06390ebe58 100644
--- a/lib/libthr/thread/thr_join.c
+++ b/lib/libthr/thread/thr_join.c
@@ -92,19 +92,12 @@ _pthread_tryjoin_np(pthread_t pthread, void **thread_return)
return (join_common(pthread, thread_return, NULL, false, true));
}
-static void
-join_common_joined(struct pthread *pthread, struct pthread *curthread,
- void **thread_return)
+static void *
+join_common_detach(struct pthread *pthread)
{
- void *tmp;
-
- tmp = pthread->ret;
pthread->flags |= THR_FLAGS_DETACHED;
pthread->joiner = NULL;
- _thr_try_gc(curthread, pthread); /* thread lock released */
-
- if (thread_return != NULL)
- *thread_return = tmp;
+ return (pthread->ret);
}
/*
@@ -117,6 +110,7 @@ join_common(pthread_t pthread, void **thread_return,
{
struct pthread *curthread = _get_curthread();
struct timespec ts, ts2, *tsp;
+ void *tmp;
long tid;
int ret;
@@ -156,7 +150,10 @@ join_common(pthread_t pthread, void **thread_return,
THR_THREAD_UNLOCK(curthread, pthread);
return (EBUSY);
}
- join_common_joined(pthread, curthread, thread_return);
+ tmp = join_common_detach(pthread);
+ _thr_try_gc(curthread, pthread); /* thread lock released */
+ if (thread_return != NULL)
+ *thread_return = tmp;
return (0);
}
@@ -193,8 +190,17 @@ join_common(pthread_t pthread, void **thread_return,
backout_join(pthread, curthread);
} else {
ret = 0;
+ THREAD_LIST_WRLOCK(curthread);
THR_THREAD_LOCK(curthread, pthread);
- join_common_joined(pthread, curthread, thread_return);
+ tmp = join_common_detach(pthread);
+ if (THR_SHOULD_GC(pthread)) {
+ THR_LIST_REMOVE(pthread);
+ THR_GCLIST_ADD(pthread);
+ }
+ THR_THREAD_UNLOCK(curthread, pthread);
+ THREAD_LIST_UNLOCK(curthread);
+ if (thread_return != NULL)
+ *thread_return = tmp;
}
return (ret);
}