From owner-svn-src-all@FreeBSD.ORG Tue Jul 14 22:51:31 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B44EC10656AB; Tue, 14 Jul 2009 22:51:31 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 88BCF8FC21; Tue, 14 Jul 2009 22:51:31 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n6EMpV4N073614; Tue, 14 Jul 2009 22:51:31 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n6EMpVrt073612; Tue, 14 Jul 2009 22:51:31 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <200907142251.n6EMpVrt073612@svn.freebsd.org> From: Konstantin Belousov Date: Tue, 14 Jul 2009 22:51:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r195701 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jul 2009 22:51:32 -0000 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) { /*