Module Name: src
Committed By: riastradh
Date: Wed Apr 13 08:31:00 UTC 2016
Modified Files:
src/sys/kern: subr_psref.c
Log Message:
Split psref_held into internal and public variants.
For internal use, we expect psrefs to be held by other LWPs when
asking in the cross-call thread whether the target in question is
referenced.
For public use, the caller should not assert about some other LWP
holding a psref.
But the rest of the logic is the same.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/kern/subr_psref.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/subr_psref.c
diff -u src/sys/kern/subr_psref.c:1.3 src/sys/kern/subr_psref.c:1.4
--- src/sys/kern/subr_psref.c:1.3 Mon Apr 11 13:52:23 2016
+++ src/sys/kern/subr_psref.c Wed Apr 13 08:31:00 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_psref.c,v 1.3 2016/04/11 13:52:23 riastradh Exp $ */
+/* $NetBSD: subr_psref.c,v 1.4 2016/04/13 08:31:00 riastradh Exp $ */
/*-
* Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.3 2016/04/11 13:52:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_psref.c,v 1.4 2016/04/13 08:31:00 riastradh Exp $");
#include <sys/types.h>
#include <sys/condvar.h>
@@ -80,6 +80,9 @@ __KERNEL_RCSID(0, "$NetBSD: subr_psref.c
LIST_HEAD(psref_head, psref);
+static bool _psref_held(const struct psref_target *, struct psref_class *,
+ bool);
+
/*
* struct psref_class
*
@@ -370,7 +373,7 @@ psreffed_p_xc(void *cookie0, void *cooki
* after xc_wait, which has already issued any necessary memory
* barriers.
*/
- if (psref_held(P->target, P->class))
+ if (_psref_held(P->target, P->class, true))
P->ret = true;
}
@@ -430,14 +433,9 @@ psref_target_destroy(struct psref_target
target->prt_class = NULL;
}
-/*
- * psref_held(target, class)
- *
- * True if the current CPU holds a passive reference to target,
- * false otherwise. May be used only inside assertions.
- */
-bool
-psref_held(const struct psref_target *target, struct psref_class *class)
+static bool
+_psref_held(const struct psref_target *target, struct psref_class *class,
+ bool lwp_mismatch_ok)
{
const struct psref_cpu *pcpu;
const struct psref *psref;
@@ -460,7 +458,7 @@ psref_held(const struct psref_target *ta
/* Search through all the references on this CPU. */
LIST_FOREACH(psref, &pcpu->pcpu_head, psref_entry) {
/* Sanity-check the reference. */
- KASSERTMSG((psref->psref_lwp == curlwp),
+ KASSERTMSG((lwp_mismatch_ok || psref->psref_lwp == curlwp),
"passive reference transferred from lwp %p to lwp %p",
psref->psref_lwp, curlwp);
KASSERTMSG((psref->psref_cpu == curcpu()),
@@ -480,3 +478,16 @@ psref_held(const struct psref_target *ta
return held;
}
+
+/*
+ * psref_held(target, class)
+ *
+ * True if the current CPU holds a passive reference to target,
+ * false otherwise. May be used only inside assertions.
+ */
+bool
+psref_held(const struct psref_target *target, struct psref_class *class)
+{
+
+ return _psref_held(target, class, false);
+}