static inline int poll_teardown(FAR struct pollfd *fds, nfds_t nfds, int *count) { int status; int ret = OK; int i; /* Process each descriptor in the list */ *count = 0; for (i = 0; i < nfds; i++) { /* Teardown the poll */ status = poll_fdsetup(fds[i].fd, &fds[i], false); if (status < 0) { ret = status; } /* Check if any events were posted */ if (fds[i].revents != 0) { (*count)++; } /* Un-initialize the poll structure */ fds[i].sem = NULL; } return ret; }
static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds, sem_t *sem) { int ret; int i; /* Process each descriptor in the list */ for (i = 0; i < nfds; i++) { /* Setup the poll descriptor */ fds[i].sem = sem; fds[i].revents = 0; fds[i].priv = NULL; /* Set up the poll */ ret = poll_fdsetup(fds[i].fd, &fds[i], true); if (ret < 0) { return ret; } } return OK; }
static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds, sem_t *sem) { unsigned int i; int ret; /* Process each descriptor in the list */ for (i = 0; i < nfds; i++) { /* Setup the poll descriptor */ fds[i].sem = sem; fds[i].revents = 0; fds[i].priv = NULL; /* Check for invalid descriptors. "If the value of fd is less than 0, * events shall be ignored, and revents shall be set to 0 in that entry * on return from poll()." * * NOTE: There is a potential problem here. If there is only one fd * and if it is negative, then poll will hang. From my reading of the * spec, that appears to be the correct behavior. */ if (fds[i].fd >= 0) { /* Set up the poll on this valid file descriptor */ ret = poll_fdsetup(fds[i].fd, &fds[i], true); if (ret < 0) { return ret; } } } return OK; }