fs/poll: using callback mechanism to implement poll notification
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
This commit is contained in:
parent
b3e300f8e6
commit
e9ccab2db3
@ -365,10 +365,7 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (eph->poll[0].sem)
|
||||
{
|
||||
poll_notify(&eph->poll, 1, eph->poll[0].events);
|
||||
}
|
||||
poll_notify(&eph->poll, 1, eph->poll[0].events);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -90,6 +90,37 @@ static int poll_fdsetup(int fd, FAR struct pollfd *fds, bool setup)
|
||||
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
|
||||
*
|
||||
@ -118,7 +149,8 @@ static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds,
|
||||
* on each thread.
|
||||
*/
|
||||
|
||||
fds[i].sem = sem;
|
||||
fds[i].arg = sem;
|
||||
fds[i].cb = poll_default_cb;
|
||||
fds[i].revents = 0;
|
||||
fds[i].priv = NULL;
|
||||
fds[i].events |= POLLERR | POLLHUP;
|
||||
@ -267,7 +299,8 @@ static inline int poll_teardown(FAR struct pollfd *fds, nfds_t nfds,
|
||||
|
||||
/* Un-initialize the poll structure */
|
||||
|
||||
fds[i].sem = NULL;
|
||||
fds[i].arg = NULL;
|
||||
fds[i].cb = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@ -297,7 +330,6 @@ static inline int poll_teardown(FAR struct pollfd *fds, nfds_t nfds,
|
||||
void poll_notify(FAR struct pollfd **afds, int nfds, pollevent_t eventset)
|
||||
{
|
||||
int i;
|
||||
int semcount;
|
||||
FAR struct pollfd *fds;
|
||||
|
||||
DEBUGASSERT(afds != NULL && nfds >= 1);
|
||||
@ -317,15 +349,10 @@ void poll_notify(FAR struct pollfd **afds, int nfds, pollevent_t eventset)
|
||||
fds->revents &= ~POLLOUT;
|
||||
}
|
||||
|
||||
if (fds->revents != 0)
|
||||
if (fds->revents != 0 && fds->cb != NULL)
|
||||
{
|
||||
finfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
|
||||
nxsem_get_value(fds->sem, &semcount);
|
||||
if (semcount < 1)
|
||||
{
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
fds->cb(fds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -97,6 +97,11 @@ typedef unsigned int nfds_t;
|
||||
|
||||
typedef uint32_t pollevent_t;
|
||||
|
||||
/* The poll callback type */
|
||||
|
||||
struct pollfd;
|
||||
typedef CODE void (*pollcb_t)(FAR struct pollfd *fds);
|
||||
|
||||
/* This is the NuttX variant of the standard pollfd structure. The poll()
|
||||
* interfaces receive a variable length array of such structures.
|
||||
*
|
||||
@ -117,7 +122,8 @@ struct pollfd
|
||||
/* Non-standard fields used internally by NuttX. */
|
||||
|
||||
FAR void *ptr; /* The psock or file being polled */
|
||||
FAR sem_t *sem; /* Pointer to semaphore used to post output event */
|
||||
FAR void *arg; /* The poll callback function argument */
|
||||
pollcb_t cb; /* The poll callback function */
|
||||
FAR void *priv; /* For use by drivers */
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user