mirror of
https://github.com/apache/nuttx.git
synced 2026-05-18 00:34:10 +08:00
fs_epoll: support extend the epoll dynamicly.
1. epoll_ctl(EPOLL_CTL_ADD) support extend the epoll events dynamicly; 2. enhance the epoll performance by moving some poll setup and teardown process to the EPOLL_CTL_ADD/DEL/MOD; Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
This commit is contained in:
+322
-126
File diff suppressed because it is too large
Load Diff
+61
-62
@@ -24,7 +24,6 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <poll.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
@@ -45,67 +44,6 @@
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: poll_fdsetup
|
||||
*
|
||||
* Description:
|
||||
* Configure (or unconfigure) one file/socket descriptor for the poll
|
||||
* operation. If fds and sem are non-null, then the poll is being setup.
|
||||
* if fds and sem are NULL, then the poll is being torn down.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int poll_fdsetup(int fd, FAR struct pollfd *fds, bool setup)
|
||||
{
|
||||
FAR struct file *filep;
|
||||
int ret;
|
||||
|
||||
/* Get the file pointer corresponding to this file descriptor */
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
DEBUGASSERT(filep != NULL);
|
||||
|
||||
/* Let file_poll() do the rest */
|
||||
|
||||
return file_poll(filep, fds, setup);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: poll_default_cb
|
||||
*
|
||||
* Description:
|
||||
* The default poll callback function, this function do the final step of
|
||||
* poll notification.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fds - The fds
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void poll_default_cb(FAR struct pollfd *fds)
|
||||
{
|
||||
int semcount = 0;
|
||||
FAR sem_t *pollsem;
|
||||
|
||||
if (fds->arg != NULL)
|
||||
{
|
||||
pollsem = (FAR sem_t *)fds->arg;
|
||||
nxsem_get_value(pollsem, &semcount);
|
||||
if (semcount < 1)
|
||||
{
|
||||
nxsem_post(pollsem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: poll_setup
|
||||
*
|
||||
@@ -294,6 +232,67 @@ static inline int poll_teardown(FAR struct pollfd *fds, nfds_t nfds,
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: poll_fdsetup
|
||||
*
|
||||
* Description:
|
||||
* Configure (or unconfigure) one file/socket descriptor for the poll
|
||||
* operation. If fds and sem are non-null, then the poll is being setup.
|
||||
* if fds and sem are NULL, then the poll is being torn down.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int poll_fdsetup(int fd, FAR struct pollfd *fds, bool setup)
|
||||
{
|
||||
FAR struct file *filep;
|
||||
int ret;
|
||||
|
||||
/* Get the file pointer corresponding to this file descriptor */
|
||||
|
||||
ret = fs_getfilep(fd, &filep);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
DEBUGASSERT(filep != NULL);
|
||||
|
||||
/* Let file_poll() do the rest */
|
||||
|
||||
return file_poll(filep, fds, setup);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: poll_default_cb
|
||||
*
|
||||
* Description:
|
||||
* The default poll callback function, this function do the final step of
|
||||
* poll notification.
|
||||
*
|
||||
* Input Parameters:
|
||||
* fds - The fds
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void poll_default_cb(FAR struct pollfd *fds)
|
||||
{
|
||||
int semcount = 0;
|
||||
FAR sem_t *pollsem;
|
||||
|
||||
if (fds->arg != NULL)
|
||||
{
|
||||
pollsem = (FAR sem_t *)fds->arg;
|
||||
nxsem_get_value(pollsem, &semcount);
|
||||
if (semcount < 1)
|
||||
{
|
||||
nxsem_post(pollsem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: poll_notify
|
||||
*
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <signal.h>
|
||||
#include <semaphore.h>
|
||||
@@ -150,6 +151,8 @@ int ppoll(FAR struct pollfd *fds, nfds_t nfds,
|
||||
FAR const struct timespec *timeout_ts,
|
||||
FAR const sigset_t *sigmask);
|
||||
|
||||
int poll_fdsetup(int fd, FAR struct pollfd *fds, bool setup);
|
||||
void poll_default_cb(FAR struct pollfd *fds);
|
||||
void poll_notify(FAR struct pollfd **afds, int nfds, pollevent_t eventset);
|
||||
|
||||
#undef EXTERN
|
||||
|
||||
Reference in New Issue
Block a user