Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Split psref_held into internal and public variants.



details:   https://anonhg.NetBSD.org/src/rev/c9d4b9e8f0e5
branches:  trunk
changeset: 814873:c9d4b9e8f0e5
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Apr 13 08:31:00 2016 +0000

description:
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.

diffstat:

 sys/kern/subr_psref.c |  35 +++++++++++++++++++++++------------
 1 files changed, 23 insertions(+), 12 deletions(-)

diffs (81 lines):

diff -r d619377f9883 -r c9d4b9e8f0e5 sys/kern/subr_psref.c
--- a/sys/kern/subr_psref.c     Wed Apr 13 07:59:05 2016 +0000
+++ b/sys/kern/subr_psref.c     Wed Apr 13 08:31:00 2016 +0000
@@ -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 @@
 
 LIST_HEAD(psref_head, psref);
 
+static bool    _psref_held(const struct psref_target *, struct psref_class *,
+                   bool);
+
 /*
  * struct psref_class
  *
@@ -370,7 +373,7 @@
         * 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 @@
        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 @@
        /* 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 @@
 
        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);
+}



Home | Main Index | Thread Index | Old Index