fs/vfs: Implement epoll_pwait API

specified here:
https://linux.die.net/man/2/epoll_pwait

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I20106fdbe4f403ded7eab43f3523edd262e1d9a3
This commit is contained in:
Xiang Xiao 2020-08-17 01:00:36 +08:00 committed by Abdelatif Guettouche
parent cf3ecdd31b
commit 6c9ff72b9a
2 changed files with 42 additions and 16 deletions

View File

@ -203,18 +203,11 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)
}
/****************************************************************************
* Name: epoll_wait
*
* Description:
*
* Input Parameters:
*
* Returned Value:
*
* Name: epoll_pwait
****************************************************************************/
int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents,
int timeout)
int epoll_pwait(int epfd, FAR struct epoll_event *evs,
int maxevents, int timeout, FAR const sigset_t *sigmask)
{
/* REVISIT: This will not work on machines where:
* sizeof(struct epoll_head *) > sizeof(int)
@ -225,7 +218,21 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents,
int rc;
int i;
rc = poll((FAR struct pollfd *)eph->evs, eph->occupied, timeout);
if (timeout < 0)
{
rc = ppoll((FAR struct pollfd *)eph->evs,
eph->occupied, NULL, sigmask);
}
else
{
struct timespec timeout_ts;
timeout_ts.tv_sec = timeout / 1000;
timeout_ts.tv_nsec = timeout % 1000 * 1000;
rc = ppoll((FAR struct pollfd *)eph->evs,
eph->occupied, &timeout_ts, sigmask);
}
if (rc <= 0)
{
@ -262,3 +269,20 @@ int epoll_wait(int epfd, FAR struct epoll_event *evs, int maxevents,
return i;
}
/****************************************************************************
* Name: epoll_wait
*
* Description:
*
* Input Parameters:
*
* Returned Value:
*
****************************************************************************/
int epoll_wait(int epfd, FAR struct epoll_event *evs,
int maxevents, int timeout)
{
return epoll_pwait(epfd, evs, maxevents, timeout, NULL);
}

View File

@ -80,13 +80,13 @@ enum EPOLL_EVENTS
enum
{
EPOLL_CLOEXEC = 02000000
EPOLL_CLOEXEC = 02000000
#define EPOLL_CLOEXEC EPOLL_CLOEXEC
};
typedef union poll_data
{
void *ptr;
FAR void *ptr;
int fd;
uint32_t u32;
} epoll_data_t;
@ -99,7 +99,7 @@ struct epoll_event
/* Non-standard fields used internally by NuttX. */
pollevent_t revents; /* The output event flags */
void *reserved; /* reserved field sync with struct pollfd */
FAR void *reserved; /* reserved field sync with struct pollfd */
FAR sem_t *sem; /* Pointer to semaphore used to post output event */
FAR void *priv; /* For use by drivers */
};
@ -117,9 +117,11 @@ struct epoll_head
int epoll_create(int size);
int epoll_create1(int flags);
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev);
int epoll_wait(int epfd, struct epoll_event *evs,
int epoll_ctl(int epfd, int op, int fd, FAR struct epoll_event *ev);
int epoll_wait(int epfd, FAR struct epoll_event *evs,
int maxevents, int timeout);
int epoll_pwait(int epfd, FAR struct epoll_event *evs,
int maxevents, int timeout, FAR const sigset_t *sigmask);
void epoll_close(int epfd);