pipe: check for writers first in case of pipe empty

This commit is contained in:
spiriou 2020-09-21 11:41:20 +02:00 committed by Xiang Xiao
parent a128995eab
commit 65bb956e5e
1 changed files with 8 additions and 8 deletions

View File

@ -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();