Date: Tue, 14 Jul 2009 22:51:31 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r195701 - head/sys/kern Message-ID: <200907142251.n6EMpVrt073612@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Tue Jul 14 22:51:31 2009 New Revision: 195701 URL: http://svn.freebsd.org/changeset/base/195701 Log: 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) Modified: head/sys/kern/kern_thread.c Modified: head/sys/kern/kern_thread.c ============================================================================== --- head/sys/kern/kern_thread.c Tue Jul 14 22:50:41 2009 (r195700) +++ head/sys/kern/kern_thread.c Tue Jul 14 22:51:31 2009 (r195701) @@ -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) { /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200907142251.n6EMpVrt073612>