Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Add sigswitch_unlock_and_switch_away(), extracted f...



details:   https://anonhg.NetBSD.org/src/rev/17a135ecac8a
branches:  trunk
changeset: 460211:17a135ecac8a
user:      kamil <kamil%NetBSD.org@localhost>
date:      Sun Oct 13 03:10:22 2019 +0000

description:
Add sigswitch_unlock_and_switch_away(), extracted from sigswitch()

Use sigswitch_unlock_and_switch_away() whenever there is no need for
sigswitch().

diffstat:

 sys/kern/kern_sig.c |  44 +++++++++++++++++++++++++++++++-------------
 1 files changed, 31 insertions(+), 13 deletions(-)

diffs (113 lines):

diff -r 632e1a935cf6 -r 17a135ecac8a sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c       Sun Oct 13 01:17:24 2019 +0000
+++ b/sys/kern/kern_sig.c       Sun Oct 13 03:10:22 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sig.c,v 1.369 2019/10/12 19:57:09 kamil Exp $     */
+/*     $NetBSD: kern_sig.c,v 1.370 2019/10/13 03:10:22 kamil Exp $     */
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.369 2019/10/12 19:57:09 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.370 2019/10/13 03:10:22 kamil Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_dtrace.h"
@@ -126,6 +126,7 @@
 static int     sigput(sigpend_t *, struct proc *, ksiginfo_t *);
 static int     sigunwait(struct proc *, const ksiginfo_t *);
 static void    sigswitch(int, int, bool);
+static void    sigswitch_unlock_and_switch_away(struct lwp *);
 
 static void    sigacts_poolpage_free(struct pool *, void *);
 static void    *sigacts_poolpage_alloc(struct pool *, int);
@@ -932,10 +933,11 @@
         * The process is already stopping.
         */
        if ((p->p_sflag & PS_STOPPING) != 0) {
-               sigswitch(0, p->p_xsig, true);
+               mutex_exit(proc_lock);
+               sigswitch_unlock_and_switch_away(l);
                mutex_enter(proc_lock);
                mutex_enter(p->p_lock);
-               goto repeat; /* XXX */
+               goto repeat;
        }
 
        mask = &l->l_sigmask;
@@ -1642,10 +1644,11 @@
         * The process is already stopping.
         */
        if ((p->p_sflag & PS_STOPPING) != 0) {
-               sigswitch(0, p->p_xsig, true);
+               mutex_exit(proc_lock);
+               sigswitch_unlock_and_switch_away(l);
                mutex_enter(proc_lock);
                mutex_enter(p->p_lock);
-               goto repeat; /* XXX */
+               goto repeat;
        }
 
        KSI_INIT_TRAP(&ksi);
@@ -1692,7 +1695,6 @@
 {
        struct lwp *l = curlwp;
        struct proc *p = l->l_proc;
-       int biglocks;
 
        KASSERT(mutex_owned(p->p_lock));
        KASSERT(l->l_stat == LSONPROC);
@@ -1752,10 +1754,26 @@
                mutex_exit(proc_lock);
        }
 
-       /*
-        * Unlock and switch away.
-        */
+       sigswitch_unlock_and_switch_away(l);
+}
+
+/*
+ * Unlock and switch away.
+ */
+static void
+sigswitch_unlock_and_switch_away(struct lwp *l)
+{
+       struct proc *p;
+       int biglocks;
+
+       p = l->l_proc;
+
+       KASSERT(mutex_owned(p->p_lock));
        KASSERT(!mutex_owned(proc_lock));
+
+       KASSERT(l->l_stat == LSONPROC);
+       KASSERT(p->p_nrlwps > 0);
+
        KERNEL_UNLOCK_ALL(l, &biglocks);
        if (p->p_stat == SSTOP || (p->p_sflag & PS_STOPPING) != 0) {
                p->p_nrlwps--;
@@ -1845,7 +1863,7 @@
                 * we awaken, check for a signal from the debugger.
                 */
                if (p->p_stat == SSTOP || (p->p_sflag & PS_STOPPING) != 0) {
-                       sigswitch(PS_NOCLDSTOP, 0, false);
+                       sigswitch_unlock_and_switch_away(l);
                        mutex_enter(p->p_lock);
                        signo = sigchecktrace();
                } else if (p->p_stat == SACTIVE)
@@ -2527,9 +2545,9 @@
         * The process is already stopping.
         */
        if ((p->p_sflag & PS_STOPPING) != 0) {
-               sigswitch(0, p->p_xsig, false);
+               sigswitch_unlock_and_switch_away(l);
                mutex_enter(p->p_lock);
-               goto repeat; /* XXX */
+               goto repeat;
        }
 
        /* Needed for ktrace */



Home | Main Index | Thread Index | Old Index