mirror of
https://github.com/apache/nuttx.git
synced 2026-05-29 04:19:37 +08:00
poll: add poll_notify() api and call it in all drivers
Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
This commit is contained in:
@@ -73,44 +73,6 @@ static int pipecommon_semtake(FAR sem_t *sem)
|
||||
return nxsem_wait_uninterruptible(sem);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pipecommon_pollnotify
|
||||
****************************************************************************/
|
||||
|
||||
static void pipecommon_pollnotify(FAR struct pipe_dev_s *dev,
|
||||
pollevent_t eventset)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (eventset & POLLERR)
|
||||
{
|
||||
eventset &= ~(POLLOUT | POLLIN);
|
||||
}
|
||||
|
||||
for (i = 0; i < CONFIG_DEV_PIPE_NPOLLWAITERS; i++)
|
||||
{
|
||||
FAR struct pollfd *fds = dev->d_fds[i];
|
||||
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= eventset & (fds->events | POLLERR | POLLHUP);
|
||||
|
||||
if ((fds->revents & (POLLOUT | POLLHUP)) == (POLLOUT | POLLHUP))
|
||||
{
|
||||
/* POLLOUT and POLLHUP are mutually exclusive. */
|
||||
|
||||
fds->revents &= ~POLLOUT;
|
||||
}
|
||||
|
||||
if (fds->revents != 0)
|
||||
{
|
||||
finfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@@ -321,7 +283,7 @@ int pipecommon_close(FAR struct file *filep)
|
||||
{
|
||||
/* Inform poll readers that other end closed. */
|
||||
|
||||
pipecommon_pollnotify(dev, POLLHUP);
|
||||
poll_notify(dev->d_fds, CONFIG_DEV_PIPE_NPOLLWAITERS, POLLHUP);
|
||||
|
||||
while (nxsem_get_value(&dev->d_rdsem, &sval) == 0 && sval <= 0)
|
||||
{
|
||||
@@ -342,7 +304,8 @@ int pipecommon_close(FAR struct file *filep)
|
||||
{
|
||||
/* Inform poll writers that other end closed. */
|
||||
|
||||
pipecommon_pollnotify(dev, POLLERR);
|
||||
poll_notify(dev->d_fds, CONFIG_DEV_PIPE_NPOLLWAITERS,
|
||||
POLLERR);
|
||||
while (nxsem_get_value(&dev->d_wrsem, &sval) == 0
|
||||
&& sval <= 0)
|
||||
{
|
||||
@@ -477,7 +440,7 @@ ssize_t pipecommon_read(FAR struct file *filep, FAR char *buffer, size_t len)
|
||||
|
||||
/* Notify all poll/select waiters that they can write to the FIFO */
|
||||
|
||||
pipecommon_pollnotify(dev, POLLOUT);
|
||||
poll_notify(dev->d_fds, CONFIG_DEV_PIPE_NPOLLWAITERS, POLLOUT);
|
||||
|
||||
/* Notify all waiting writers that bytes have been removed from the
|
||||
* buffer.
|
||||
@@ -588,7 +551,7 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer,
|
||||
* FIFO.
|
||||
*/
|
||||
|
||||
pipecommon_pollnotify(dev, POLLIN);
|
||||
poll_notify(dev->d_fds, CONFIG_DEV_PIPE_NPOLLWAITERS, POLLIN);
|
||||
|
||||
/* Yes.. Notify all of the waiting readers that more data is
|
||||
* available.
|
||||
@@ -617,7 +580,7 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer,
|
||||
* FIFO.
|
||||
*/
|
||||
|
||||
pipecommon_pollnotify(dev, POLLIN);
|
||||
poll_notify(dev->d_fds, CONFIG_DEV_PIPE_NPOLLWAITERS, POLLIN);
|
||||
|
||||
/* Yes.. Notify all of the waiting readers that more data is
|
||||
* available.
|
||||
@@ -761,10 +724,7 @@ int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
eventset |= POLLERR;
|
||||
}
|
||||
|
||||
if (eventset)
|
||||
{
|
||||
pipecommon_pollnotify(dev, eventset);
|
||||
}
|
||||
poll_notify(dev->d_fds, CONFIG_DEV_PIPE_NPOLLWAITERS, eventset);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user