mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +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:
@@ -279,24 +279,13 @@ static uint16_t ads7843e_sendcmd(FAR struct ads7843e_dev_s *priv,
|
||||
|
||||
static void ads7843e_notify(FAR struct ads7843e_dev_s *priv)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* If there are threads waiting on poll() for ADS7843E data to become
|
||||
* available, then wake them up now. NOTE: we wake up all waiting threads
|
||||
* because we do not know that they are going to do. If they all try to
|
||||
* read the data, then some make end up blocking after all.
|
||||
*/
|
||||
|
||||
for (i = 0; i < CONFIG_ADS7843E_NPOLLWAITERS; i++)
|
||||
{
|
||||
struct pollfd *fds = priv->fds[i];
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= POLLIN;
|
||||
iinfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
poll_notify(priv->fds, CONFIG_ADS7843E_NPOLLWAITERS, POLLIN);
|
||||
|
||||
/* If there are threads waiting for read data, then signal one of them
|
||||
* that the read data is available.
|
||||
|
||||
@@ -223,7 +223,6 @@ static void ajoy_sample(FAR struct ajoy_upperhalf_s *priv)
|
||||
ajoy_buttonset_t press;
|
||||
ajoy_buttonset_t release;
|
||||
irqstate_t flags;
|
||||
int i;
|
||||
|
||||
DEBUGASSERT(priv);
|
||||
lower = priv->au_lower;
|
||||
@@ -265,19 +264,8 @@ static void ajoy_sample(FAR struct ajoy_upperhalf_s *priv)
|
||||
|
||||
/* Yes.. Notify all waiters */
|
||||
|
||||
for (i = 0; i < CONFIG_INPUT_AJOYSTICK_NPOLLWAITERS; i++)
|
||||
{
|
||||
FAR struct pollfd *fds = opriv->ao_fds[i];
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= (fds->events & POLLIN);
|
||||
if (fds->revents != 0)
|
||||
{
|
||||
iinfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
}
|
||||
poll_notify(opriv->ao_fds, CONFIG_INPUT_AJOYSTICK_NPOLLWAITERS,
|
||||
POLLIN);
|
||||
}
|
||||
|
||||
/* Have any signal events occurred? */
|
||||
@@ -635,12 +623,7 @@ static int ajoy_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
|
||||
if (opriv->ao_pollpending)
|
||||
{
|
||||
fds->revents |= (fds->events & POLLIN);
|
||||
if (fds->revents != 0)
|
||||
{
|
||||
iinfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
poll_notify(&fds, 1, POLLIN);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -230,7 +230,6 @@ static void btn_sample(FAR struct btn_upperhalf_s *priv)
|
||||
btn_buttonset_t change;
|
||||
btn_buttonset_t press;
|
||||
btn_buttonset_t release;
|
||||
int i;
|
||||
|
||||
DEBUGASSERT(priv && priv->bu_lower);
|
||||
lower = priv->bu_lower;
|
||||
@@ -267,19 +266,8 @@ static void btn_sample(FAR struct btn_upperhalf_s *priv)
|
||||
{
|
||||
/* Yes.. Notify all waiters */
|
||||
|
||||
for (i = 0; i < CONFIG_INPUT_BUTTONS_NPOLLWAITERS; i++)
|
||||
{
|
||||
FAR struct pollfd *fds = opriv->bo_fds[i];
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= (fds->events & POLLIN);
|
||||
if (fds->revents != 0)
|
||||
{
|
||||
iinfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
}
|
||||
poll_notify(opriv->bo_fds, CONFIG_INPUT_BUTTONS_NPOLLWAITERS,
|
||||
POLLIN);
|
||||
}
|
||||
|
||||
/* Have any signal events occurred? */
|
||||
@@ -687,12 +675,7 @@ static int btn_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
|
||||
if (opriv->bo_pending)
|
||||
{
|
||||
fds->revents |= (fds->events & POLLIN);
|
||||
if (fds->revents != 0)
|
||||
{
|
||||
iinfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
poll_notify(&fds, 1, POLLIN);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -981,25 +981,6 @@ static int mbr3108_close(FAR struct file *filep)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mbr3108_poll_notify(FAR struct mbr3108_dev_s *priv)
|
||||
{
|
||||
int i;
|
||||
|
||||
DEBUGASSERT(priv != NULL);
|
||||
|
||||
for (i = 0; i < CONFIG_INPUT_CYPRESS_MBR3108_NPOLLWAITERS; i++)
|
||||
{
|
||||
struct pollfd *fds = priv->fds[i];
|
||||
if (fds)
|
||||
{
|
||||
mbr3108_dbg("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
|
||||
fds->revents |= POLLIN;
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int mbr3108_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
bool setup)
|
||||
{
|
||||
@@ -1059,7 +1040,9 @@ static int mbr3108_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
pending = priv->int_pending;
|
||||
if (pending)
|
||||
{
|
||||
mbr3108_poll_notify(priv);
|
||||
poll_notify(priv->fds,
|
||||
CONFIG_INPUT_CYPRESS_MBR3108_NPOLLWAITERS,
|
||||
POLLIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1092,7 +1075,7 @@ static int mbr3108_isr_handler(int irq, FAR void *context, FAR void *arg)
|
||||
priv->int_pending = true;
|
||||
leave_critical_section(flags);
|
||||
|
||||
mbr3108_poll_notify(priv);
|
||||
poll_notify(priv->fds, CONFIG_INPUT_CYPRESS_MBR3108_NPOLLWAITERS, POLLIN);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -223,7 +223,6 @@ static void djoy_sample(FAR struct djoy_upperhalf_s *priv)
|
||||
djoy_buttonset_t press;
|
||||
djoy_buttonset_t release;
|
||||
irqstate_t flags;
|
||||
int i;
|
||||
|
||||
DEBUGASSERT(priv);
|
||||
lower = priv->du_lower;
|
||||
@@ -265,19 +264,8 @@ static void djoy_sample(FAR struct djoy_upperhalf_s *priv)
|
||||
|
||||
/* Yes.. Notify all waiters */
|
||||
|
||||
for (i = 0; i < CONFIG_INPUT_DJOYSTICK_NPOLLWAITERS; i++)
|
||||
{
|
||||
FAR struct pollfd *fds = opriv->do_fds[i];
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= (fds->events & POLLIN);
|
||||
if (fds->revents != 0)
|
||||
{
|
||||
iinfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
}
|
||||
poll_notify(opriv->do_fds, CONFIG_INPUT_DJOYSTICK_NPOLLWAITERS,
|
||||
POLLIN);
|
||||
}
|
||||
|
||||
/* Have any signal events occurred? */
|
||||
@@ -629,12 +617,7 @@ static int djoy_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
|
||||
if (opriv->do_pollpending)
|
||||
{
|
||||
fds->revents |= (fds->events & POLLIN);
|
||||
if (fds->revents != 0)
|
||||
{
|
||||
iinfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
poll_notify(&fds, 1, POLLIN);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
+1
-12
@@ -201,24 +201,13 @@ static const uint8_t g_event_map[4] =
|
||||
|
||||
static void ft5x06_notify(FAR struct ft5x06_dev_s *priv)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* If there are threads waiting on poll() for FT5x06 data to become
|
||||
* available, then wake them up now. NOTE: we wake up all waiting threads
|
||||
* because we do not know that they are going to do. If they all try to
|
||||
* read the data, then some make end up blocking after all.
|
||||
*/
|
||||
|
||||
for (i = 0; i < CONFIG_FT5X06_NPOLLWAITERS; i++)
|
||||
{
|
||||
struct pollfd *fds = priv->fds[i];
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= POLLIN;
|
||||
iinfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
poll_notify(priv->fds, CONFIG_FT5X06_NPOLLWAITERS, POLLIN);
|
||||
|
||||
/* If there are threads waiting for read data, then signal one of them
|
||||
* that the read data is available.
|
||||
|
||||
@@ -75,7 +75,6 @@ static ssize_t keyboard_write(FAR struct file *filep, FAR const char *buffer,
|
||||
size_t len);
|
||||
static int keyboard_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
bool setup);
|
||||
static void keyboard_notify(FAR struct keyboard_opriv_s *buffer);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
@@ -99,30 +98,6 @@ static const struct file_operations g_keyboard_fops =
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: keyboard_notify
|
||||
****************************************************************************/
|
||||
|
||||
static void keyboard_notify(FAR struct keyboard_opriv_s *opriv)
|
||||
{
|
||||
FAR struct pollfd *fds = opriv->fds;
|
||||
if (fds != NULL)
|
||||
{
|
||||
fds->revents |= (fds->events & POLLIN);
|
||||
if (fds->revents != 0)
|
||||
{
|
||||
/* report event log */
|
||||
|
||||
int semcount;
|
||||
nxsem_get_value(fds->sem, &semcount);
|
||||
if (semcount < 1)
|
||||
{
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: keyboard_open
|
||||
****************************************************************************/
|
||||
@@ -301,7 +276,7 @@ static int keyboard_poll(FAR struct file *filep,
|
||||
|
||||
if (!circbuf_is_empty(&opriv->circ))
|
||||
{
|
||||
keyboard_notify(opriv);
|
||||
poll_notify(&opriv->fds, 1, POLLIN);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -437,7 +412,7 @@ void keyboard_event(FAR struct keyboard_lowerhalf_s *lower, uint32_t keycode,
|
||||
nxsem_post(&opriv->waitsem);
|
||||
}
|
||||
|
||||
keyboard_notify(opriv);
|
||||
poll_notify(&opriv->fds, 1, POLLIN);
|
||||
nxsem_post(&opriv->locksem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,24 +236,13 @@ static uint16_t max11802_sendcmd(FAR struct max11802_dev_s *priv,
|
||||
|
||||
static void max11802_notify(FAR struct max11802_dev_s *priv)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* If there are threads waiting on poll() for MAX11802 data to become
|
||||
* available, then wake them up now. NOTE: we wake up all waiting
|
||||
* threads because we do not know that they are going to do. If they
|
||||
* all try to read the data, then some make end up blocking after all.
|
||||
*/
|
||||
|
||||
for (i = 0; i < CONFIG_MAX11802_NPOLLWAITERS; i++)
|
||||
{
|
||||
struct pollfd *fds = priv->fds[i];
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= POLLIN;
|
||||
iinfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
poll_notify(priv->fds, CONFIG_MAX11802_NPOLLWAITERS, POLLIN);
|
||||
|
||||
/* If there are threads waiting for read data, then signal one of them
|
||||
* that the read data is available.
|
||||
|
||||
+1
-12
@@ -584,24 +584,13 @@ static int mxt_flushmsgs(FAR struct mxt_dev_s *priv)
|
||||
|
||||
static void mxt_notify(FAR struct mxt_dev_s *priv)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* If there are threads waiting on poll() for maXTouch data to become
|
||||
* available, then wake them up now. NOTE: we wake up all waiting threads
|
||||
* because we do not know that they are going to do. If they all try to
|
||||
* read the data, then some make end up blocking after all.
|
||||
*/
|
||||
|
||||
for (i = 0; i < CONFIG_MXT_NPOLLWAITERS; i++)
|
||||
{
|
||||
struct pollfd *fds = priv->fds[i];
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= POLLIN;
|
||||
iinfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
poll_notify(priv->fds, CONFIG_MXT_NPOLLWAITERS, POLLIN);
|
||||
|
||||
/* If there are threads waiting for read data, then signal one of them
|
||||
* that the read data is available.
|
||||
|
||||
@@ -440,29 +440,6 @@ static int spq10kbd_interrupt(int irq, FAR void *context, FAR void *arg)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: spq10kbd_pollnotify
|
||||
****************************************************************************/
|
||||
|
||||
static void spq10kbd_pollnotify(FAR struct spq10kbd_dev_s *priv)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < CONFIG_SPQ10KBD_NPOLLWAITERS; i++)
|
||||
{
|
||||
struct pollfd *fds = priv->fds[i];
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= (fds->events & POLLIN);
|
||||
if (fds->revents != 0)
|
||||
{
|
||||
uinfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: spq10kbd_open
|
||||
*
|
||||
@@ -676,7 +653,7 @@ static int spq10kbd_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
|
||||
if (priv->headndx != priv->tailndx)
|
||||
{
|
||||
spq10kbd_pollnotify(priv);
|
||||
poll_notify(priv->fds, CONFIG_SPQ10KBD_NPOLLWAITERS, POLLIN);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -145,24 +145,13 @@ static const struct file_operations g_stmpe811fops =
|
||||
|
||||
static void stmpe811_notify(FAR struct stmpe811_dev_s *priv)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* If there are threads waiting on poll() for STMPE811 data to become
|
||||
* available, then wake them up now. NOTE: we wake up all waiting threads
|
||||
* because we do not know that they are going to do. If they all try to
|
||||
* read the data, then some make end up blocking after all.
|
||||
*/
|
||||
|
||||
for (i = 0; i < CONFIG_STMPE811_NPOLLWAITERS; i++)
|
||||
{
|
||||
struct pollfd *fds = priv->fds[i];
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= POLLIN;
|
||||
iinfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
poll_notify(priv->fds, CONFIG_STMPE811_NPOLLWAITERS, POLLIN);
|
||||
|
||||
/* If there are threads waiting for read data, then signal one of them
|
||||
* that the read data is available.
|
||||
|
||||
@@ -66,8 +66,6 @@ struct touch_upperhalf_s
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void touch_notify(FAR struct touch_openpriv_s *openpriv,
|
||||
pollevent_t eventset);
|
||||
static int touch_open(FAR struct file *filep);
|
||||
static int touch_close(FAR struct file *filep);
|
||||
static ssize_t touch_read(FAR struct file *filep, FAR char *buffer,
|
||||
@@ -101,29 +99,6 @@ static const struct file_operations g_touch_fops =
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void touch_notify(FAR struct touch_openpriv_s *openpriv,
|
||||
pollevent_t eventset)
|
||||
{
|
||||
FAR struct pollfd *fd = openpriv->fds;
|
||||
|
||||
fd = openpriv->fds;
|
||||
if (fd)
|
||||
{
|
||||
fd->revents |= (fd->events & eventset);
|
||||
if (fd->revents != 0)
|
||||
{
|
||||
/* report event log */
|
||||
|
||||
int semcount;
|
||||
nxsem_get_value(fd->sem, &semcount);
|
||||
if (semcount < 1)
|
||||
{
|
||||
nxsem_post(fd->sem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: touch_open
|
||||
****************************************************************************/
|
||||
@@ -323,13 +298,10 @@ static int touch_poll(FAR struct file *filep, struct pollfd *fds, bool setup)
|
||||
|
||||
if (!circbuf_is_empty(&openpriv->circbuf))
|
||||
{
|
||||
eventset |= (fds->events & POLLIN);
|
||||
eventset |= POLLIN;
|
||||
}
|
||||
|
||||
if (eventset)
|
||||
{
|
||||
touch_notify(openpriv, POLLIN);
|
||||
}
|
||||
poll_notify(&openpriv->fds, 1, eventset);
|
||||
}
|
||||
else if (fds->priv)
|
||||
{
|
||||
@@ -368,7 +340,7 @@ void touch_event(FAR void *priv, FAR const struct touch_sample_s *sample)
|
||||
nxsem_post(&openpriv->waitsem);
|
||||
}
|
||||
|
||||
touch_notify(openpriv, POLLIN);
|
||||
poll_notify(&openpriv->fds, 1, POLLIN);
|
||||
}
|
||||
|
||||
nxsem_post(&upper->exclsem);
|
||||
|
||||
+1
-12
@@ -237,24 +237,13 @@ static struct tsc2007_dev_s *g_tsc2007list;
|
||||
|
||||
static void tsc2007_notify(FAR struct tsc2007_dev_s *priv)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* If there are threads waiting on poll() for TSC2007 data to become
|
||||
* available, then wake them up now. NOTE: we wake up all waiting
|
||||
* threads because we do not know that they are going to do. If they
|
||||
* all try to read the data, then some make end up blocking after all.
|
||||
*/
|
||||
|
||||
for (i = 0; i < CONFIG_TSC2007_NPOLLWAITERS; i++)
|
||||
{
|
||||
struct pollfd *fds = priv->fds[i];
|
||||
if (fds)
|
||||
{
|
||||
fds->revents |= POLLIN;
|
||||
iinfo("Report events: %08" PRIx32 "\n", fds->revents);
|
||||
nxsem_post(fds->sem);
|
||||
}
|
||||
}
|
||||
poll_notify(priv->fds, CONFIG_TSC2007_NPOLLWAITERS, POLLIN);
|
||||
|
||||
/* If there are threads waiting for read data, then signal one of them
|
||||
* that the read data is available.
|
||||
|
||||
Reference in New Issue
Block a user