summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thr_detach.c
diff options
context:
space:
mode:
authorjasone <jasone@FreeBSD.org>2001-05-20 23:08:33 +0000
committerjasone <jasone@FreeBSD.org>2001-05-20 23:08:33 +0000
commitadf603d4b170a8622047e0fd342070ac6f07caf4 (patch)
treec37f9e05a6d81f226bfef98090c73e613802b9c7 /lib/libpthread/thread/thr_detach.c
parentcdb5d97b478a3e4f97dd6c0cd43105d0951daed5 (diff)
downloadFreeBSD-src-adf603d4b170a8622047e0fd342070ac6f07caf4.zip
FreeBSD-src-adf603d4b170a8622047e0fd342070ac6f07caf4.tar.gz
Instead of using a join queue for each thread, use a single pointer to
keep track of a joiner. POSIX only supports a single joiner, so this simplification is acceptable. At the same time, make sure to mark a joined thread as detached so that its resources can be freed. Reviewed by: deischen PR: 24345
Diffstat (limited to 'lib/libpthread/thread/thr_detach.c')
-rw-r--r--lib/libpthread/thread/thr_detach.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/libpthread/thread/thr_detach.c b/lib/libpthread/thread/thr_detach.c
index 0b3cfd7..b0e6fc4 100644
--- a/lib/libpthread/thread/thr_detach.c
+++ b/lib/libpthread/thread/thr_detach.c
@@ -41,7 +41,6 @@ int
_pthread_detach(pthread_t pthread)
{
int rval = 0;
- pthread_t next_thread;
/* Check for invalid calling parameters: */
if (pthread == NULL || pthread->magic != PTHREAD_MAGIC)
@@ -59,19 +58,20 @@ _pthread_detach(pthread_t pthread)
*/
_thread_kern_sig_defer();
- /* Enter a loop to bring all threads off the join queue: */
- while ((next_thread = TAILQ_FIRST(&pthread->join_queue)) != NULL) {
- /* Remove the thread from the queue: */
- TAILQ_REMOVE(&pthread->join_queue, next_thread, sqe);
- pthread->flags &= ~PTHREAD_FLAGS_IN_JOINQ;
+ /* Check if there is a joiner: */
+ if (pthread->joiner != NULL) {
+ struct pthread *joiner = pthread->joiner;
/* Make the thread runnable: */
- PTHREAD_NEW_STATE(next_thread, PS_RUNNING);
+ PTHREAD_NEW_STATE(joiner, PS_RUNNING);
+
+ /* Set the return value for the woken thread: */
+ joiner->error = ESRCH;
/*
- * Set the return value for the woken thread:
+ * Disconnect the joiner from the thread being detached:
*/
- next_thread->error = ESRCH;
+ pthread->joiner = NULL;
}
/*
OpenPOWER on IntegriCloud