summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2023-04-25 18:14:07 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2023-04-25 18:14:07 +0000
commitf773b7009b484087c2f0a2f994fdb65256d52cec (patch)
tree0806f4b710cc06bee7e64add305657aaf8b90e23 /sys/kern
parentcc093bee7fbd66d043c1f3638f3d8646522614d6 (diff)
Rename ps_refcnt to ps_threadcnt in struct process and implement
P_HASSIBLING() using this count. OK mvs@ mpi@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_exit.c11
-rw-r--r--sys/kern/kern_fork.c7
2 files changed, 10 insertions, 8 deletions
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c
index 7860c65eeda..85c5d58dc23 100644
--- a/sys/kern/kern_exit.c
+++ b/sys/kern/kern_exit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_exit.c,v 1.210 2022/12/29 01:36:36 guenther Exp $ */
+/* $OpenBSD: kern_exit.c,v 1.211 2023/04/25 18:14:06 claudio Exp $ */
/* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */
/*
@@ -159,9 +159,10 @@ exit1(struct proc *p, int xexit, int xsig, int flags)
SCHED_LOCK(s);
TAILQ_REMOVE(&pr->ps_threads, p, p_thr_link);
SCHED_UNLOCK(s);
+
if ((p->p_flag & P_THREAD) == 0) {
/* main thread gotta wait because it has the pid, et al */
- while (pr->ps_refcnt > 1)
+ while (pr->ps_threadcnt > 1)
tsleep_nsec(&pr->ps_threads, PWAIT, "thrdeath", INFSLP);
if (pr->ps_flags & PS_PROFIL)
stopprofclock(pr);
@@ -328,9 +329,9 @@ exit1(struct proc *p, int xexit, int xsig, int flags)
/* just a thread? detach it from its process */
if (p->p_flag & P_THREAD) {
/* scheduler_wait_hook(pr->ps_mainproc, p); XXX */
- if (--pr->ps_refcnt == 1)
+ if (--pr->ps_threadcnt == 1)
wakeup(&pr->ps_threads);
- KASSERT(pr->ps_refcnt > 0);
+ KASSERT(pr->ps_threadcnt > 0);
}
/* Release the thread's read reference of resource limit structure. */
@@ -814,7 +815,7 @@ process_zap(struct process *pr)
if (otvp)
vrele(otvp);
- KASSERT(pr->ps_refcnt == 1);
+ KASSERT(pr->ps_threadcnt == 1);
if (pr->ps_ptstat != NULL)
free(pr->ps_ptstat, M_SUBPROC, sizeof(*pr->ps_ptstat));
pool_put(&rusage_pool, pr->ps_ru);
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index f0f279d9f64..6c28078ebc9 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.246 2023/02/10 14:34:17 visa Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.247 2023/04/25 18:14:06 claudio Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -180,7 +180,7 @@ process_initialize(struct process *pr, struct proc *p)
pr->ps_mainproc = p;
TAILQ_INIT(&pr->ps_threads);
TAILQ_INSERT_TAIL(&pr->ps_threads, p, p_thr_link);
- pr->ps_refcnt = 1;
+ pr->ps_threadcnt = 1;
p->p_p = pr;
/* give the process the same creds as the initial thread */
@@ -539,7 +539,7 @@ thread_fork(struct proc *curp, void *stack, void *tcb, pid_t *tidptr,
/* other links */
p->p_p = pr;
- pr->ps_refcnt++;
+ pr->ps_threadcnt++;
/* local copies */
p->p_fd = pr->ps_fd;
@@ -560,6 +560,7 @@ thread_fork(struct proc *curp, void *stack, void *tcb, pid_t *tidptr,
SCHED_LOCK(s);
TAILQ_INSERT_TAIL(&pr->ps_threads, p, p_thr_link);
+
/*
* if somebody else wants to take us to single threaded mode,
* count ourselves in.