pipe: check for writers first in case of pipe empty
This commit is contained in:
parent
a128995eab
commit
65bb956e5e
|
@ -426,14 +426,6 @@ ssize_t pipecommon_read(FAR struct file *filep, FAR char *buffer, size_t len)
|
|||
|
||||
while (dev->d_wrndx == dev->d_rdndx)
|
||||
{
|
||||
/* If O_NONBLOCK was set, then return EGAIN */
|
||||
|
||||
if (filep->f_oflags & O_NONBLOCK)
|
||||
{
|
||||
nxsem_post(&dev->d_bfsem);
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
/* If there are no writers on the pipe, then return end of file */
|
||||
|
||||
if (dev->d_nwriters <= 0)
|
||||
|
@ -442,6 +434,14 @@ ssize_t pipecommon_read(FAR struct file *filep, FAR char *buffer, size_t len)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* If O_NONBLOCK was set, then return EGAIN */
|
||||
|
||||
if (filep->f_oflags & O_NONBLOCK)
|
||||
{
|
||||
nxsem_post(&dev->d_bfsem);
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
/* Otherwise, wait for something to be written to the pipe */
|
||||
|
||||
sched_lock();
|
||||
|
|
Loading…
Reference in New Issue