summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2009-07-14 22:51:31 +0000
committerkib <kib@FreeBSD.org>2009-07-14 22:51:31 +0000
commitaa9063dc970560b1ab26b34f292e63ad270cb4c4 (patch)
treece9e83962ea8ab83432f47643e3419c7a6d85c3c /sys/kern
parentbd93a0c99aeae8ceb8cb06ce8f941dd42f51b0bc (diff)
downloadFreeBSD-src-aa9063dc970560b1ab26b34f292e63ad270cb4c4.zip
FreeBSD-src-aa9063dc970560b1ab26b34f292e63ad270cb4c4.tar.gz
Move the repeated code to calculate the number of the threads in the
process that still need to be suspended or exited from thread_single into the new function calc_remaining(). Tested by: pho Reviewed by: jhb Approved by: re (kensmith)
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_thread.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c
index bb8779b..f04b2a6 100644
--- a/sys/kern/kern_thread.c
+++ b/sys/kern/kern_thread.c
@@ -504,6 +504,22 @@ thread_unlink(struct thread *td)
/* Must NOT clear links to proc! */
}
+static int
+calc_remaining(struct proc *p, int mode)
+{
+ int remaining;
+
+ if (mode == SINGLE_EXIT)
+ remaining = p->p_numthreads;
+ else if (mode == SINGLE_BOUNDARY)
+ remaining = p->p_numthreads - p->p_boundary_count;
+ else if (mode == SINGLE_NO_EXIT)
+ remaining = p->p_numthreads - p->p_suspcount;
+ else
+ panic("calc_remaining: wrong mode %d", mode);
+ return (remaining);
+}
+
/*
* Enforce single-threading.
*
@@ -551,12 +567,7 @@ thread_single(int mode)
p->p_flag |= P_STOPPED_SINGLE;
PROC_SLOCK(p);
p->p_singlethread = td;
- if (mode == SINGLE_EXIT)
- remaining = p->p_numthreads;
- else if (mode == SINGLE_BOUNDARY)
- remaining = p->p_numthreads - p->p_boundary_count;
- else
- remaining = p->p_numthreads - p->p_suspcount;
+ remaining = calc_remaining(p, mode);
while (remaining != 1) {
if (P_SHOULDSTOP(p) != P_STOPPED_SINGLE)
goto stopme;
@@ -611,12 +622,7 @@ thread_single(int mode)
}
if (wakeup_swapper)
kick_proc0();
- if (mode == SINGLE_EXIT)
- remaining = p->p_numthreads;
- else if (mode == SINGLE_BOUNDARY)
- remaining = p->p_numthreads - p->p_boundary_count;
- else
- remaining = p->p_numthreads - p->p_suspcount;
+ remaining = calc_remaining(p, mode);
/*
* Maybe we suspended some threads.. was it enough?
@@ -630,12 +636,7 @@ stopme:
* In the mean time we suspend as well.
*/
thread_suspend_switch(td);
- if (mode == SINGLE_EXIT)
- remaining = p->p_numthreads;
- else if (mode == SINGLE_BOUNDARY)
- remaining = p->p_numthreads - p->p_boundary_count;
- else
- remaining = p->p_numthreads - p->p_suspcount;
+ remaining = calc_remaining(p, mode);
}
if (mode == SINGLE_EXIT) {
/*
OpenPOWER on IntegriCloud