Thu Jan 30 12:36:38 2020 UTC ()
Update comments


(ad)
diff -r1.74 -r1.75 src/sys/kern/sys_lwp.c

cvs diff -r1.74 -r1.75 src/sys/kern/sys_lwp.c (expand / switch to unified diff)

--- src/sys/kern/sys_lwp.c 2020/01/29 15:47:52 1.74
+++ src/sys/kern/sys_lwp.c 2020/01/30 12:36:38 1.75
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sys_lwp.c,v 1.74 2020/01/29 15:47:52 ad Exp $ */ 1/* $NetBSD: sys_lwp.c,v 1.75 2020/01/30 12:36:38 ad Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2001, 2006, 2007, 2008, 2019, 2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2001, 2006, 2007, 2008, 2019, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Nathan J. Williams, and Andrew Doran. 8 * by Nathan J. Williams, and Andrew Doran.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * Lightweight process (LWP) system calls. See kern_lwp.c for a description 33 * Lightweight process (LWP) system calls. See kern_lwp.c for a description
34 * of LWPs. 34 * of LWPs.
35 */ 35 */
36 36
37#include <sys/cdefs.h> 37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.74 2020/01/29 15:47:52 ad Exp $"); 38__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.75 2020/01/30 12:36:38 ad Exp $");
39 39
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/systm.h> 41#include <sys/systm.h>
42#include <sys/pool.h> 42#include <sys/pool.h>
43#include <sys/proc.h> 43#include <sys/proc.h>
44#include <sys/types.h> 44#include <sys/types.h>
45#include <sys/syscallargs.h> 45#include <sys/syscallargs.h>
46#include <sys/kauth.h> 46#include <sys/kauth.h>
47#include <sys/kmem.h> 47#include <sys/kmem.h>
48#include <sys/ptrace.h> 48#include <sys/ptrace.h>
49#include <sys/sleepq.h> 49#include <sys/sleepq.h>
50#include <sys/lwpctl.h> 50#include <sys/lwpctl.h>
51#include <sys/cpu.h> 51#include <sys/cpu.h>
@@ -470,35 +470,41 @@ lwp_unpark(const lwpid_t *tp, const u_in @@ -470,35 +470,41 @@ lwp_unpark(const lwpid_t *tp, const u_in
470 rw_enter(&p->p_treelock, RW_READER); 470 rw_enter(&p->p_treelock, RW_READER);
471 for (target = 0; target < ntargets; target++) { 471 for (target = 0; target < ntargets; target++) {
472 /* 472 /*
473 * We don't bother excluding zombies or idle LWPs here, as 473 * We don't bother excluding zombies or idle LWPs here, as
474 * setting LW_UNPARKED on them won't do any harm. 474 * setting LW_UNPARKED on them won't do any harm.
475 */ 475 */
476 id = (uint64_t)(tp[target] - 1); 476 id = (uint64_t)(tp[target] - 1);
477 t = radix_tree_lookup_node(&p->p_lwptree, id); 477 t = radix_tree_lookup_node(&p->p_lwptree, id);
478 if (t == NULL) { 478 if (t == NULL) {
479 error = ESRCH; 479 error = ESRCH;
480 continue; 480 continue;
481 } 481 }
482 482
483 /* It may not have parked yet or we may have raced. */ 
484 lwp_lock(t); 483 lwp_lock(t);
485 if (t->l_syncobj == &lwp_park_syncobj) { 484 if (t->l_syncobj == &lwp_park_syncobj) {
486 /* Releases the LWP lock. */ 485 /*
 486 * As expected it's parked, so wake it up.
 487 * lwp_unsleep() will release the LWP lock.
 488 */
487 lwp_unsleep(t, true); 489 lwp_unsleep(t, true);
488 } else { 490 } else {
489 /* 491 /*
490 * Set the operation pending. The next call to 492 * It hasn't parked yet because the wakeup side won
491 * _lwp_park() will return early. 493 * the race, or something else has happened to make
 494 * the thread not park. Why doesn't really matter.
 495 * Set the operation pending, so that the next call
 496 * to _lwp_park() in the LWP returns early. If it
 497 * turns out to be a spurious wakeup, no harm done.
492 */ 498 */
493 t->l_flag |= LW_UNPARKED; 499 t->l_flag |= LW_UNPARKED;
494 lwp_unlock(t); 500 lwp_unlock(t);
495 } 501 }
496 } 502 }
497 rw_exit(&p->p_treelock); 503 rw_exit(&p->p_treelock);
498 504
499 return error; 505 return error;
500} 506}
501 507
502int 508int
503lwp_park(clockid_t clock_id, int flags, struct timespec *ts) 509lwp_park(clockid_t clock_id, int flags, struct timespec *ts)
504{ 510{