This is an automated email from the ASF dual-hosted git repository. pkarashchenko pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit cf21319d3abca30221d53937d6a36dc86976ccf7 Author: Xiang Xiao <xiaoxi...@xiaomi.com> AuthorDate: Wed Oct 26 13:50:25 2022 +0800 fs: Remove the unused nx_poll to prefer file_poll for kernel Signed-off-by: Xiang Xiao <xiaoxi...@xiaomi.com> --- fs/vfs/fs_poll.c | 88 +++++++++++++++++++-------------------------------- fs/vfs/fs_select.c | 35 ++++---------------- include/nuttx/fs/fs.h | 17 ---------- 3 files changed, 39 insertions(+), 101 deletions(-) diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index 0a33961361..1b7c36b7a3 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -410,21 +410,37 @@ int file_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) } /**************************************************************************** - * Name: nx_poll + * Name: poll * * Description: - * nx_poll() is similar to the standard 'poll' interface except that is - * not a cancellation point and it does not modify the errno variable. + * poll() waits for one of a set of file descriptors to become ready to + * perform I/O. If none of the events requested (and no error) has + * occurred for any of the file descriptors, then poll() blocks until + * one of the events occurs. * - * nx_poll() is an internal NuttX interface and should not be called from - * applications. + * Input Parameters: + * fds - List of structures describing file descriptors to be monitored + * nfds - The number of entries in the list + * timeout - Specifies an upper limit on the time for which poll() will + * block in milliseconds. A negative value of timeout means an infinite + * timeout. * * Returned Value: - * Zero is returned on success; a negated value is returned on any failure. + * On success, the number of structures that have non-zero revents fields. + * A value of 0 indicates that the call timed out and no file descriptors + * were ready. On error, -1 is returned, and errno is set appropriately: + * + * EBADF - An invalid file descriptor was given in one of the sets. + * EFAULT - The fds address is invalid + * EINTR - A signal occurred before any requested event. + * EINVAL - The nfds value exceeds a system limit. + * ENOMEM - There was no space to allocate internal data structures. + * ENOSYS - One or more of the drivers supporting the file descriptor + * does not support the poll method. * ****************************************************************************/ -int nx_poll(FAR struct pollfd *fds, unsigned int nfds, int timeout) +int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout) { sem_t sem; int count = 0; @@ -433,6 +449,10 @@ int nx_poll(FAR struct pollfd *fds, unsigned int nfds, int timeout) DEBUGASSERT(nfds == 0 || fds != NULL); + /* poll() is a cancellation point */ + + enter_cancellation_point(); + nxsem_init(&sem, 0, 0); ret = poll_setup(fds, nfds, &sem); if (ret >= 0) @@ -508,57 +528,15 @@ int nx_poll(FAR struct pollfd *fds, unsigned int nfds, int timeout) } nxsem_destroy(&sem); - return ret < 0 ? ret : count; -} - -/**************************************************************************** - * Name: poll - * - * Description: - * poll() waits for one of a set of file descriptors to become ready to - * perform I/O. If none of the events requested (and no error) has - * occurred for any of the file descriptors, then poll() blocks until - * one of the events occurs. - * - * Input Parameters: - * fds - List of structures describing file descriptors to be monitored - * nfds - The number of entries in the list - * timeout - Specifies an upper limit on the time for which poll() will - * block in milliseconds. A negative value of timeout means an infinite - * timeout. - * - * Returned Value: - * On success, the number of structures that have non-zero revents fields. - * A value of 0 indicates that the call timed out and no file descriptors - * were ready. On error, -1 is returned, and errno is set appropriately: - * - * EBADF - An invalid file descriptor was given in one of the sets. - * EFAULT - The fds address is invalid - * EINTR - A signal occurred before any requested event. - * EINVAL - The nfds value exceeds a system limit. - * ENOMEM - There was no space to allocate internal data structures. - * ENOSYS - One or more of the drivers supporting the file descriptor - * does not support the poll method. - * - ****************************************************************************/ - -int poll(FAR struct pollfd *fds, nfds_t nfds, int timeout) -{ - int ret; - - /* poll() is a cancellation point */ - - enter_cancellation_point(); - - /* Let nx_poll() do all of the work */ + leave_cancellation_point(); - ret = nx_poll(fds, nfds, timeout); if (ret < 0) { set_errno(-ret); - ret = ERROR; + return ERROR; + } + else + { + return count; } - - leave_cancellation_point(); - return ret; } diff --git a/fs/vfs/fs_select.c b/fs/vfs/fs_select.c index 908a7863d8..cffbb06f06 100644 --- a/fs/vfs/fs_select.c +++ b/fs/vfs/fs_select.c @@ -79,21 +79,16 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds, FAR fd_set *exceptfds, FAR struct timeval *timeout) { struct pollfd *pollset = NULL; - int errcode = OK; int fd; int npfds; int msec; int ndx; int ret; - /* select() is cancellation point */ - - enter_cancellation_point(); - if (nfds < 0) { - errcode = EINVAL; - goto errout; + set_errno(EINVAL); + return ERROR; } /* How many pollfd structures do we need to allocate? */ @@ -123,8 +118,8 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds, if (pollset == NULL) { - errcode = ENOMEM; - goto errout; + set_errno(ENOMEM); + return ERROR; } } @@ -191,13 +186,7 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds, /* Then let poll do all of the real work. */ - ret = nx_poll(pollset, npfds, msec); - if (ret < 0) - { - /* poll() failed! Save the errno value */ - - errcode = -ret; - } + ret = poll(pollset, npfds, msec); /* Now set up the return values */ @@ -263,17 +252,5 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds, } kmm_free(pollset); - - /* Did poll() fail above? */ - - if (ret >= 0) - { - leave_cancellation_point(); - return ret; - } - -errout: - set_errno(errcode); - leave_cancellation_point(); - return ERROR; + return ret; } diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index a95dd2dd43..973bbd89f9 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -1354,23 +1354,6 @@ int nx_fcntl(int fd, int cmd, ...); int file_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup); -/**************************************************************************** - * Name: nx_poll - * - * Description: - * nx_poll() is similar to the standard 'poll' interface except that is - * not a cancellation point and it does not modify the errno variable. - * - * nx_poll() is an internal NuttX interface and should not be called from - * applications. - * - * Returned Value: - * Zero is returned on success; a negated value is returned on any failure. - * - ****************************************************************************/ - -int nx_poll(FAR struct pollfd *fds, unsigned int nfds, int timeout); - /**************************************************************************** * Name: file_fstat *