From owner-svn-src-all@FreeBSD.ORG Wed Oct 20 00:41:38 2010 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 9F7A8106566B; Wed, 20 Oct 2010 00:41:38 +0000 (UTC) (envelope-from davidxu@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8D88B8FC16; Wed, 20 Oct 2010 00:41:38 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o9K0fccE032227; Wed, 20 Oct 2010 00:41:38 GMT (envelope-from davidxu@svn.freebsd.org) Received: (from davidxu@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o9K0fcJT032225; Wed, 20 Oct 2010 00:41:38 GMT (envelope-from davidxu@svn.freebsd.org) Message-Id: <201010200041.o9K0fcJT032225@svn.freebsd.org> From: David Xu Date: Wed, 20 Oct 2010 00:41:38 +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: r214091 - 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: Wed, 20 Oct 2010 00:41:38 -0000 Author: davidxu Date: Wed Oct 20 00:41:38 2010 New Revision: 214091 URL: http://svn.freebsd.org/changeset/base/214091 Log: - Don't include sx.h, it is not needed. - Check NULL pointer, move timeout calculation code outside of process lock. Modified: head/sys/kern/kern_thr.c Modified: head/sys/kern/kern_thr.c ============================================================================== --- head/sys/kern/kern_thr.c Wed Oct 20 00:24:30 2010 (r214090) +++ head/sys/kern/kern_thr.c Wed Oct 20 00:41:38 2010 (r214091) @@ -45,7 +45,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -431,40 +430,40 @@ thr_suspend(struct thread *td, struct th int kern_thr_suspend(struct thread *td, struct timespec *tsp) { + struct proc *p = td->td_proc; struct timeval tv; int error = 0; int timo = 0; - if (tsp != NULL) { - if (tsp->tv_nsec < 0 || tsp->tv_nsec > 1000000000) - return (EINVAL); - } - if (td->td_pflags & TDP_WAKEUP) { td->td_pflags &= ~TDP_WAKEUP; return (0); } - PROC_LOCK(td->td_proc); - if ((td->td_flags & TDF_THRWAKEUP) == 0) { + if (tsp != NULL) { + if (tsp->tv_nsec < 0 || tsp->tv_nsec > 1000000000) + return (EINVAL); if (tsp->tv_sec == 0 && tsp->tv_nsec == 0) error = EWOULDBLOCK; else { TIMESPEC_TO_TIMEVAL(&tv, tsp); timo = tvtohz(&tv); - error = msleep((void *)td, &td->td_proc->p_mtx, - PCATCH, "lthr", timo); } } + PROC_LOCK(p); + if (error == 0 && (td->td_flags & TDF_THRWAKEUP) == 0) + error = msleep((void *)td, &p->p_mtx, + PCATCH, "lthr", timo); + if (td->td_flags & TDF_THRWAKEUP) { thread_lock(td); td->td_flags &= ~TDF_THRWAKEUP; thread_unlock(td); - PROC_UNLOCK(td->td_proc); + PROC_UNLOCK(p); return (0); } - PROC_UNLOCK(td->td_proc); + PROC_UNLOCK(p); if (error == EWOULDBLOCK) error = ETIMEDOUT; else if (error == ERESTART) {