mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
pollnotify: we should send poll events before semaphore incrementes.
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>
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
13e10504c9
commit
d452a05910
@@ -136,8 +136,8 @@ ssize_t nxterm_read(FAR struct file *filep, FAR char *buffer, size_t len)
|
||||
break;
|
||||
}
|
||||
|
||||
/* If the driver was opened with O_NONBLOCK option, then don't wait.
|
||||
* Just return EGAIN.
|
||||
/* If the driver was opened with O_NONBLOCK option, then
|
||||
* don't wait. Just return EGAIN.
|
||||
*/
|
||||
|
||||
if (filep->f_oflags & O_NONBLOCK)
|
||||
@@ -147,8 +147,9 @@ ssize_t nxterm_read(FAR struct file *filep, FAR char *buffer, size_t len)
|
||||
}
|
||||
|
||||
/* Otherwise, wait for something to be written to the circular
|
||||
* buffer. Increment the number of waiters so that the nxterm_write()
|
||||
* will not that it needs to post the semaphore to wake us up.
|
||||
* buffer. Increment the number of waiters so that the
|
||||
* nxterm_write() will not that it needs to post the semaphore
|
||||
* to wake us up.
|
||||
*/
|
||||
|
||||
sched_lock();
|
||||
@@ -162,8 +163,8 @@ ssize_t nxterm_read(FAR struct file *filep, FAR char *buffer, size_t len)
|
||||
|
||||
ret = nxsem_wait(&priv->waitsem);
|
||||
|
||||
/* Pre-emption will be disabled when we return. So the decrementing
|
||||
* nwaiters here is safe.
|
||||
/* Pre-emption will be disabled when we return. So the
|
||||
* decrementing nwaiters here is safe.
|
||||
*/
|
||||
|
||||
priv->nwaiters--;
|
||||
@@ -313,15 +314,14 @@ int nxterm_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup)
|
||||
/* Check if the receive buffer is empty */
|
||||
|
||||
if (priv->head != priv->tail)
|
||||
{
|
||||
eventset |= POLLIN;
|
||||
}
|
||||
{
|
||||
eventset |= POLLIN;
|
||||
}
|
||||
|
||||
if (eventset)
|
||||
{
|
||||
nxterm_pollnotify(priv, eventset);
|
||||
}
|
||||
|
||||
}
|
||||
else if (fds->priv)
|
||||
{
|
||||
@@ -429,7 +429,9 @@ void nxterm_kbdin(NXTERM handle, FAR const uint8_t *buffer, uint8_t buflen)
|
||||
|
||||
if (nexthead == priv->tail)
|
||||
{
|
||||
/* Yes... Return an indication that nothing was saved in the buffer. */
|
||||
/* Yes... Return an indication that nothing was saved in
|
||||
* the buffer.
|
||||
*/
|
||||
|
||||
gerr("ERROR: Keyboard data overrun\n");
|
||||
break;
|
||||
@@ -450,16 +452,20 @@ void nxterm_kbdin(NXTERM handle, FAR const uint8_t *buffer, uint8_t buflen)
|
||||
/* Are there threads waiting for read data? */
|
||||
|
||||
sched_lock();
|
||||
for (i = 0; i < priv->nwaiters; i++)
|
||||
{
|
||||
/* Yes.. Notify all of the waiting readers that more data is available */
|
||||
|
||||
nxsem_post(&priv->waitsem);
|
||||
}
|
||||
|
||||
/* Notify all poll/select waiters that they can read from the FIFO */
|
||||
|
||||
nxterm_pollnotify(priv, POLLIN);
|
||||
|
||||
for (i = 0; i < priv->nwaiters; i++)
|
||||
{
|
||||
/* Yes.. Notify all of the waiting readers that more data is
|
||||
* available
|
||||
*/
|
||||
|
||||
nxsem_post(&priv->waitsem);
|
||||
}
|
||||
|
||||
sched_unlock();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user