diff options
author | pjd <pjd@FreeBSD.org> | 2012-06-09 18:03:23 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2012-06-09 18:03:23 +0000 |
commit | b9def82bd780b376d5d8385bbcf875c9fa0a6bfd (patch) | |
tree | 8390aafa6740ab0a0ee92d7ee61021dd49e1e9e3 /sys/kern/kern_descrip.c | |
parent | 76ab178d5a7c5c31da9fe74db1de8b9a649188f3 (diff) | |
download | FreeBSD-src-b9def82bd780b376d5d8385bbcf875c9fa0a6bfd.zip FreeBSD-src-b9def82bd780b376d5d8385bbcf875c9fa0a6bfd.tar.gz |
Make some of the loops more readable.
Reviewed by: tegge
MFC after: 1 month
Diffstat (limited to 'sys/kern/kern_descrip.c')
-rw-r--r-- | sys/kern/kern_descrip.c | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index dc703e7..e3b90af 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -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); } |