Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Restore curlwp->l_name in threadpool_job_done(), ra...
details: https://anonhg.NetBSD.org/src/rev/1c12a59ba74d
branches: trunk
changeset: 837918:1c12a59ba74d
user: thorpej <thorpej%NetBSD.org@localhost>
date: Thu Dec 27 04:45:29 2018 +0000
description:
Restore curlwp->l_name in threadpool_job_done(), rather than after the
job function has returned. This lays the groundwork for some job object
reference counting change that will be coming in a subsequent comment.
diffstat:
sys/kern/kern_threadpool.c | 35 +++++++++++++++++++++++------------
1 files changed, 23 insertions(+), 12 deletions(-)
diffs (78 lines):
diff -r a56df05fe3f4 -r 1c12a59ba74d sys/kern/kern_threadpool.c
--- a/sys/kern/kern_threadpool.c Thu Dec 27 02:54:00 2018 +0000
+++ b/sys/kern/kern_threadpool.c Thu Dec 27 04:45:29 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_threadpool.c,v 1.11 2018/12/26 22:16:26 thorpej Exp $ */
+/* $NetBSD: kern_threadpool.c,v 1.12 2018/12/27 04:45:29 thorpej Exp $ */
/*-
* Copyright (c) 2014, 2018 The NetBSD Foundation, Inc.
@@ -81,7 +81,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_threadpool.c,v 1.11 2018/12/26 22:16:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_threadpool.c,v 1.12 2018/12/27 04:45:29 thorpej Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -107,6 +107,7 @@
struct threadpool_thread {
struct lwp *tpt_lwp;
+ char *tpt_lwp_savedname;
struct threadpool *tpt_pool;
struct threadpool_job *tpt_job;
kcondvar_t tpt_cv;
@@ -693,6 +694,15 @@
KASSERT(job->job_thread != NULL);
KASSERT(job->job_thread->tpt_lwp == curlwp);
+ /*
+ * We can safely read this field; it's only modified right before
+ * we call the job work function, and we are only preserving it
+ * to use here; no one cares if it contains junk afterward.
+ */
+ lwp_lock(curlwp);
+ curlwp->l_name = job->job_thread->tpt_lwp_savedname;
+ lwp_unlock(curlwp);
+
cv_broadcast(&job->job_cv);
job->job_thread = NULL;
}
@@ -977,24 +987,25 @@
struct threadpool_job *const job = thread->tpt_job;
KASSERT(job != NULL);
+
+ /* Set our lwp name to reflect what job we're doing. */
+ lwp_lock(curlwp);
+ char *const lwp_name __diagused = curlwp->l_name;
+ thread->tpt_lwp_savedname = curlwp->l_name;
+ curlwp->l_name = job->job_name;
+ lwp_unlock(curlwp);
+
mutex_spin_exit(&pool->tp_lock);
TP_LOG(("%s: running job '%s' on thread %p.\n",
__func__, job->job_name, thread));
- /* Set our lwp name to reflect what job we're doing. */
- lwp_lock(curlwp);
- char *const lwp_name = curlwp->l_name;
- curlwp->l_name = job->job_name;
- lwp_unlock(curlwp);
-
/* Run the job. */
(*job->job_fn)(job);
- /* Restore our lwp name. */
- lwp_lock(curlwp);
- curlwp->l_name = lwp_name;
- lwp_unlock(curlwp);
+ /* lwp name restored in threadpool_job_done(). */
+ KASSERTMSG((curlwp->l_name == lwp_name),
+ "someone forgot to call threadpool_job_done()!");
/* Job is done and its name is unreferenced. Release it. */
threadpool_job_rele(job);
Home |
Main Index |
Thread Index |
Old Index