Sun Apr 19 23:05:05 2020 UTC ()
lwp_wait(): don't need to check for process exit, cv_wait_sig() does it.


(ad)
diff -r1.233 -r1.234 src/sys/kern/kern_lwp.c

cvs diff -r1.233 -r1.234 src/sys/kern/kern_lwp.c (expand / switch to unified diff)

--- src/sys/kern/kern_lwp.c 2020/04/04 20:20:12 1.233
+++ src/sys/kern/kern_lwp.c 2020/04/19 23:05:04 1.234
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: kern_lwp.c,v 1.233 2020/04/04 20:20:12 thorpej Exp $ */ 1/* $NetBSD: kern_lwp.c,v 1.234 2020/04/19 23:05:04 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020 4 * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2019, 2020
5 * The NetBSD Foundation, Inc. 5 * The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation 8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Nathan J. Williams, and Andrew Doran. 9 * by Nathan J. Williams, and Andrew Doran.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -201,27 +201,27 @@ @@ -201,27 +201,27 @@
201 * (But not always for kernel threads. There are some special cases 201 * (But not always for kernel threads. There are some special cases
202 * as mentioned above: soft interrupts, and the idle loops.) 202 * as mentioned above: soft interrupts, and the idle loops.)
203 * 203 *
204 * Note that an LWP is considered running or likely to run soon if in 204 * Note that an LWP is considered running or likely to run soon if in
205 * one of the following states. This affects the value of p_nrlwps: 205 * one of the following states. This affects the value of p_nrlwps:
206 * 206 *
207 * LSRUN, LSONPROC, LSSLEEP 207 * LSRUN, LSONPROC, LSSLEEP
208 * 208 *
209 * p_lock does not need to be held when transitioning among these 209 * p_lock does not need to be held when transitioning among these
210 * three states, hence p_lock is rarely taken for state transitions. 210 * three states, hence p_lock is rarely taken for state transitions.
211 */ 211 */
212 212
213#include <sys/cdefs.h> 213#include <sys/cdefs.h>
214__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.233 2020/04/04 20:20:12 thorpej Exp $"); 214__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.234 2020/04/19 23:05:04 ad Exp $");
215 215
216#include "opt_ddb.h" 216#include "opt_ddb.h"
217#include "opt_lockdebug.h" 217#include "opt_lockdebug.h"
218#include "opt_dtrace.h" 218#include "opt_dtrace.h"
219 219
220#define _LWP_API_PRIVATE 220#define _LWP_API_PRIVATE
221 221
222#include <sys/param.h> 222#include <sys/param.h>
223#include <sys/systm.h> 223#include <sys/systm.h>
224#include <sys/cpu.h> 224#include <sys/cpu.h>
225#include <sys/pool.h> 225#include <sys/pool.h>
226#include <sys/proc.h> 226#include <sys/proc.h>
227#include <sys/syscallargs.h> 227#include <sys/syscallargs.h>
@@ -730,33 +730,31 @@ lwp_wait(struct lwp *l, lwpid_t lid, lwp @@ -730,33 +730,31 @@ lwp_wait(struct lwp *l, lwpid_t lid, lwp
730 } 730 }
731 731
732 /* 732 /*
733 * Note: since the lock will be dropped, need to restart on 733 * Note: since the lock will be dropped, need to restart on
734 * wakeup to run all LWPs again, e.g. there may be new LWPs. 734 * wakeup to run all LWPs again, e.g. there may be new LWPs.
735 */ 735 */
736 if (exiting) { 736 if (exiting) {
737 KASSERT(p->p_nlwps > 1); 737 KASSERT(p->p_nlwps > 1);
738 error = cv_timedwait(&p->p_lwpcv, p->p_lock, 1); 738 error = cv_timedwait(&p->p_lwpcv, p->p_lock, 1);
739 break; 739 break;
740 } 740 }
741 741
742 /* 742 /*
743 * Break out if the process is exiting, or if all LWPs are 743 * Break out if all LWPs are in _lwp_wait(). There are
744 * in _lwp_wait(). There are other ways to hang the process 744 * other ways to hang the process with _lwp_wait(), but the
745 * with _lwp_wait(), but the sleep is interruptable so 745 * sleep is interruptable so little point checking for them.
746 * little point checking for them. 
747 */ 746 */
748 if ((p->p_sflag & PS_WEXIT) != 0 || 747 if (p->p_nlwpwait == p->p_nlwps) {
749 p->p_nlwpwait == p->p_nlwps) { 
750 error = EDEADLK; 748 error = EDEADLK;
751 break; 749 break;
752 } 750 }
753 751
754 /* 752 /*
755 * Sit around and wait for something to happen. We'll be  753 * Sit around and wait for something to happen. We'll be
756 * awoken if any of the conditions examined change: if an 754 * awoken if any of the conditions examined change: if an
757 * LWP exits, is collected, or is detached. 755 * LWP exits, is collected, or is detached.
758 */ 756 */
759 if ((error = cv_wait_sig(&p->p_lwpcv, p->p_lock)) != 0) 757 if ((error = cv_wait_sig(&p->p_lwpcv, p->p_lock)) != 0)
760 break; 758 break;
761 } 759 }
762 760