Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Feb 2018 00:21:51 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r329419 - head/sys/kern
Message-ID:  <201802170021.w1H0LpaN029356@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Sat Feb 17 00:21:50 2018
New Revision: 329419
URL: https://svnweb.freebsd.org/changeset/base/329419

Log:
  Tidy up kern_wait6
  
  - don't relock curproc in msleep
  - don't relock proctree if P_STATCHILD is spotted
  - reformat the proc_to_reap call in the main loop

Modified:
  head/sys/kern/kern_exit.c

Modified: head/sys/kern/kern_exit.c
==============================================================================
--- head/sys/kern/kern_exit.c	Sat Feb 17 00:12:30 2018	(r329418)
+++ head/sys/kern/kern_exit.c	Sat Feb 17 00:21:50 2018	(r329419)
@@ -1202,21 +1202,21 @@ loop:
 		q->p_flag &= ~P_STATCHILD;
 		PROC_UNLOCK(q);
 	}
-	nfound = 0;
 	sx_xlock(&proctree_lock);
+loop_locked:
+	nfound = 0;
 	LIST_FOREACH(p, &q->p_children, p_sibling) {
 		pid = p->p_pid;
 		ret = proc_to_reap(td, p, idtype, id, status, options,
 		    wrusage, siginfo, 0);
 		if (ret == 0)
 			continue;
-		else if (ret == 1)
-			nfound++;
-		else {
+		else if (ret != 1) {
 			td->td_retval[0] = pid;
 			return (0);
 		}
 
+		nfound++;
 		PROC_LOCK_ASSERT(p, MA_OWNED);
 
 		if ((options & (WTRAPPED | WUNTRACED)) != 0)
@@ -1237,7 +1237,7 @@ loop:
 			report_alive_proc(td, p, siginfo, status, options,
 			    CLD_TRAPPED);
 			return (0);
-			}
+		}
 		if ((options & WUNTRACED) != 0 &&
 		    (p->p_flag & P_STOPPED_SIG) != 0 &&
 		    p->p_suspcount == p->p_numthreads &&
@@ -1293,13 +1293,13 @@ loop:
 		return (0);
 	}
 	PROC_LOCK(q);
-	sx_xunlock(&proctree_lock);
 	if (q->p_flag & P_STATCHILD) {
 		q->p_flag &= ~P_STATCHILD;
-		error = 0;
-	} else
-		error = msleep(q, &q->p_mtx, PWAIT | PCATCH, "wait", 0);
-	PROC_UNLOCK(q);
+		PROC_UNLOCK(q);
+		goto loop_locked;
+	}
+	sx_xunlock(&proctree_lock);
+	error = msleep(q, &q->p_mtx, PWAIT | PCATCH | PDROP, "wait", 0);
 	if (error)
 		return (error);
 	goto loop;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201802170021.w1H0LpaN029356>