Skip to content

Commit

Permalink
pollnotify: we should send poll events before semaphore incrementes.
Browse files Browse the repository at this point in the history
There is a good case on sim platform:
When we input some cmd and click enter key to start application in terminal,
this context will change to application from IDLE loop. Althrough entey key '\r'
has been received to recv buffer and complete post semaphore of reader, but
pollnotify may not be called because context change. So when application run
poll function, because no events happend and poll enter wait, context will
again change to IDLE loop, this pollnotify of IDLE loop will run to send poll
events, poll function of applicaton will wake up. It's wrong!

Change-Id: I812a889f2e90781a9c3cb4b0251cccc4d32bebd1
Signed-off-by: dongjiuzhu <dongjiuzhu1@xiaomi.com>
  • Loading branch information
Donny9 authored and acassis committed Oct 26, 2020
1 parent 13e1050 commit d452a05
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 219 deletions.
26 changes: 13 additions & 13 deletions arch/arm/src/sama5/sam_tsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,6 @@ static void sam_tsd_notify(struct sam_tsd_s *priv)
{
int i;

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because the
* touchscreen is no longer available.
*/

nxsem_post(&priv->waitsem);
}

/* If there are threads waiting on poll() for touchscreen 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
Expand All @@ -283,6 +270,19 @@ static void sam_tsd_notify(struct sam_tsd_s *priv)
nxsem_post(fds->sem);
}
}

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because the
* touchscreen is no longer available.
*/

nxsem_post(&priv->waitsem);
}
}

/****************************************************************************
Expand Down
32 changes: 17 additions & 15 deletions arch/sim/src/sim/up_touchscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,6 @@ static void up_notify(FAR struct up_dev_s *priv)
{
int i;

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

iinfo("contact=%d nwaiters=%d\n", priv->sample.contact, priv->nwaiters);
if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because
* the touchscreen is no longer available.
*/

nxsem_post(&priv->waitsem);
}

/* If there are threads waiting on poll() for touchscreen data to become
* available, then wake them up now. NOTE: we wake up all waiting threads
* because we do not know what they are going to do. If they all try to
Expand All @@ -211,6 +197,20 @@ static void up_notify(FAR struct up_dev_s *priv)
nxsem_post(fds->sem);
}
}

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

iinfo("contact=%d nwaiters=%d\n", priv->sample.contact, priv->nwaiters);
if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because
* the touchscreen is no longer available.
*/

nxsem_post(&priv->waitsem);
}
}

/****************************************************************************
Expand Down Expand Up @@ -239,7 +239,9 @@ static int up_sample(FAR struct up_dev_s *priv,

if (sample->contact == CONTACT_UP)
{
/* Next.. no contract. Increment the ID so that next contact ID will be unique */
/* Next.. no contract. Increment the ID so that next contact ID
* will be unique
*/

priv->sample.contact = CONTACT_NONE;
priv->id++;
Expand Down
26 changes: 13 additions & 13 deletions boards/arm/stm32/mikroe-stm32f4/src/stm32_touchscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,19 +605,6 @@ static void tc_notify(FAR struct tc_dev_s *priv)
}
#endif

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because the
* touchscreen is no longer available.
*/

nxsem_post(&priv->waitsem);
}

/* If there are threads waiting on poll() for touchscreen 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
Expand All @@ -634,6 +621,19 @@ static void tc_notify(FAR struct tc_dev_s *priv)
nxsem_post(fds->sem);
}
}

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because the
* touchscreen is no longer available.
*/

nxsem_post(&priv->waitsem);
}
}

/****************************************************************************
Expand Down
26 changes: 13 additions & 13 deletions boards/mips/pic32mx/pic32mx7mmb/src/pic32_touchscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,19 +491,6 @@ static void tc_notify(FAR struct tc_dev_s *priv)
{
int i;

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because the
* touchscreen is no longer available.
*/

nxsem_post(&priv->waitsem);
}

/* If there are threads waiting on poll() for touchscreen 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.
Expand All @@ -521,6 +508,19 @@ static void tc_notify(FAR struct tc_dev_s *priv)
nxsem_post(fds->sem);
}
}

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because the
* touchscreen is no longer available.
*/

nxsem_post(&priv->waitsem);
}
}

/****************************************************************************
Expand Down
12 changes: 6 additions & 6 deletions drivers/analog/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,12 @@ static void adc_notify(FAR struct adc_dev_s *dev)
{
FAR struct adc_fifo_s *fifo = &dev->ad_recv;

/* If there are threads waiting on poll() for data to become available,
* then wake them up now.
*/

adc_pollnotify(dev, POLLIN);

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/
Expand All @@ -495,12 +501,6 @@ static void adc_notify(FAR struct adc_dev_s *dev)
{
nxsem_post(&fifo->af_sem);
}

/* If there are threads waiting on poll() for data to become available,
* then wake them up now.
*/

adc_pollnotify(dev, POLLIN);
}

/****************************************************************************
Expand Down
24 changes: 12 additions & 12 deletions drivers/can/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,12 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr,

fifo->rx_tail = nexttail;

/* Notify all poll/select waiters that they can read from the
* cd_recv buffer
*/

can_pollnotify(dev, POLLIN);

sval = 0;
if (nxsem_get_value(&fifo->rx_sem, &sval) < 0)
{
Expand All @@ -1349,12 +1355,6 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr,
}

errcode = OK;

/* Notify all poll/select waiters that they can read from the
* cd_recv buffer
*/

can_pollnotify(dev, POLLIN);
}
#ifdef CONFIG_CAN_ERRORS
else
Expand Down Expand Up @@ -1471,6 +1471,12 @@ int can_txdone(FAR struct can_dev_s *dev)

can_xmit(dev);

/* Notify all poll/select waiters that they can write to the cd_xmit
* buffer
*/

can_pollnotify(dev, POLLOUT);

/* Are there any threads waiting for space in the TX FIFO? */

if (dev->cd_ntxwaiters > 0)
Expand All @@ -1485,12 +1491,6 @@ int can_txdone(FAR struct can_dev_s *dev)
}
}

/* Notify all poll/select waiters that they can write to the cd_xmit
* buffer
*/

can_pollnotify(dev, POLLOUT);

return ret;
}

Expand Down
26 changes: 13 additions & 13 deletions drivers/input/ads7843e.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,6 @@ static void ads7843e_notify(FAR struct ads7843e_dev_s *priv)
{
int i;

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because the ADS7843E
* is no longer available.
*/

nxsem_post(&priv->waitsem);
}

/* 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
Expand All @@ -323,6 +310,19 @@ static void ads7843e_notify(FAR struct ads7843e_dev_s *priv)
nxsem_post(fds->sem);
}
}

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because the ADS7843E
* is no longer available.
*/

nxsem_post(&priv->waitsem);
}
}

/****************************************************************************
Expand Down
26 changes: 13 additions & 13 deletions drivers/input/ft5x06.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,19 +224,6 @@ static void ft5x06_notify(FAR struct ft5x06_dev_s *priv)
{
int i;

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because the FT5x06
* is no longer available.
*/

nxsem_post(&priv->waitsem);
}

/* 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
Expand All @@ -253,6 +240,19 @@ static void ft5x06_notify(FAR struct ft5x06_dev_s *priv)
nxsem_post(fds->sem);
}
}

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because the FT5x06
* is no longer available.
*/

nxsem_post(&priv->waitsem);
}
}

/****************************************************************************
Expand Down
26 changes: 13 additions & 13 deletions drivers/input/max11802.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,6 @@ static void max11802_notify(FAR struct max11802_dev_s *priv)
{
int i;

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because the sample
* is no longer available.
*/

nxsem_post(&priv->waitsem);
}

/* 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
Expand All @@ -282,6 +269,19 @@ static void max11802_notify(FAR struct max11802_dev_s *priv)
nxsem_post(fds->sem);
}
}

/* If there are threads waiting for read data, then signal one of them
* that the read data is available.
*/

if (priv->nwaiters > 0)
{
/* After posting this semaphore, we need to exit because the sample
* is no longer available.
*/

nxsem_post(&priv->waitsem);
}
}

/****************************************************************************
Expand Down
Loading

0 comments on commit d452a05

Please sign in to comment.