From owner-svn-src-head@FreeBSD.ORG Sat Jun 9 18:03:24 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 49AB01065674; Sat, 9 Jun 2012 18:03:24 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1BB4B8FC0A; Sat, 9 Jun 2012 18:03:24 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q59I3N1W046618; Sat, 9 Jun 2012 18:03:23 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q59I3Nsd046616; Sat, 9 Jun 2012 18:03:23 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201206091803.q59I3Nsd046616@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Sat, 9 Jun 2012 18:03:23 +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: r236820 - head/sys/kern X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Jun 2012 18:03:24 -0000 Author: pjd Date: Sat Jun 9 18:03:23 2012 New Revision: 236820 URL: http://svn.freebsd.org/changeset/base/236820 Log: Make some of the loops more readable. Reviewed by: tegge MFC after: 1 month Modified: head/sys/kern/kern_descrip.c Modified: head/sys/kern/kern_descrip.c ============================================================================== --- head/sys/kern/kern_descrip.c Sat Jun 9 17:39:05 2012 (r236819) +++ head/sys/kern/kern_descrip.c Sat Jun 9 18:03:23 2012 (r236820) @@ -1570,7 +1570,6 @@ fdavail(struct thread *td, int n) { struct proc *p = td->td_proc; struct filedesc *fdp = td->td_proc->p_fd; - struct file **fpp; int i, lim, last; FILEDESC_LOCK_ASSERT(fdp); @@ -1586,9 +1585,8 @@ fdavail(struct thread *td, int n) if ((i = lim - fdp->fd_nfiles) > 0 && (n -= i) <= 0) return (1); last = min(fdp->fd_nfiles, lim); - fpp = &fdp->fd_ofiles[fdp->fd_freefile]; - for (i = last - fdp->fd_freefile; --i >= 0; fpp++) { - if (*fpp == NULL && --n <= 0) + for (i = fdp->fd_freefile; i < last; i++) { + if (fdp->fd_ofiles[i] == NULL && --n <= 0) return (1); } return (0); @@ -1874,13 +1872,10 @@ fdfree(struct thread *td) fdtol->fdl_refcount)); if (fdtol->fdl_refcount == 1 && (td->td_proc->p_leader->p_flag & P_ADVLOCK) != 0) { - for (i = 0, fpp = fdp->fd_ofiles; - i <= fdp->fd_lastfile; - i++, fpp++) { - if (*fpp == NULL || - (*fpp)->f_type != DTYPE_VNODE) + for (i = 0; i <= fdp->fd_lastfile; i++) { + fp = fdp->fd_ofiles[i]; + if (fp == NULL || fp->f_type != DTYPE_VNODE) continue; - fp = *fpp; fhold(fp); FILEDESC_XUNLOCK(fdp); lf.l_whence = SEEK_SET; @@ -1898,7 +1893,6 @@ fdfree(struct thread *td) VFS_UNLOCK_GIANT(locked); FILEDESC_XLOCK(fdp); fdrop(fp, td); - fpp = fdp->fd_ofiles + i; } } retry: @@ -1943,12 +1937,11 @@ fdfree(struct thread *td) if (i > 0) return; - fpp = fdp->fd_ofiles; - for (i = fdp->fd_lastfile; i-- >= 0; fpp++) { - if (*fpp) { + for (i = 0; i <= fdp->fd_lastfile; i++) { + fp = fdp->fd_ofiles[i]; + if (fp != NULL) { FILEDESC_XLOCK(fdp); - fp = *fpp; - *fpp = NULL; + fdp->fd_ofiles[i] = NULL; FILEDESC_XUNLOCK(fdp); (void) closef(fp, td); }