git: 60b699f99c81 - main - fd: add FILEDESC_FOREACH_{FDE,FP}
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 13 Feb 2022 13:07:19 UTC
The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=60b699f99c81fcc182c2ac7a5182545016811393 commit 60b699f99c81fcc182c2ac7a5182545016811393 Author: Mateusz Guzik <mjg@FreeBSD.org> AuthorDate: 2022-01-29 22:19:18 +0000 Commit: Mateusz Guzik <mjg@FreeBSD.org> CommitDate: 2022-02-13 13:07:08 +0000 fd: add FILEDESC_FOREACH_{FDE,FP} Right now they naively walk the fd table just like all the other code, but that's going to change. --- sys/sys/filedesc.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h index 0560a517c160..ed1f8989358e 100644 --- a/sys/sys/filedesc.h +++ b/sys/sys/filedesc.h @@ -183,6 +183,18 @@ struct filedesc_to_leader { MPASS(curproc->p_fd == _fdp); \ (curproc->p_numthreads == 1 && refcount_load(&_fdp->fd_refcnt) == 1); \ }) +#define FILEDESC_FOREACH_FDE(fdp, _iterator, _fde) \ + struct filedesc *_fdp = (fdp); \ + int _lastfile = fdlastfile_single(_fdp); \ + for (_iterator = 0; _iterator <= _lastfile; _iterator++) \ + if ((_fde = &_fdp->fd_ofiles[_iterator])->fde_file != NULL) + +#define FILEDESC_FOREACH_FP(fdp, _iterator, _fp) \ + struct filedesc *_fdp = (fdp); \ + int _lastfile = fdlastfile_single(_fdp); \ + for (_iterator = 0; _iterator <= _lastfile; _iterator++) \ + if ((_fp = _fdp->fd_ofiles[_iterator].fde_file) != NULL) + #else /*