Minor pipe updates

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@780 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2008-07-26 14:02:46 +00:00
parent b918dac0c3
commit 759ba256e8
6 changed files with 48 additions and 48 deletions

View File

@ -1510,8 +1510,8 @@ The system can be re-made subsequently by just typing <code>make</code>.
watchdog structures to minimize dynamic allocations
</li>
<li>
<code>CONFIG_DEV_FIFO_SIZE</code>: Size, in bytes, of the buffer to allocated
for FIFO support (default is 1024).
<code>CONFIG_DEV_PIPE_SIZE</code>: Size, in bytes, of the buffer to allocated
for pipe and FIFO support (default is 1024).
</li>
</ul>

View File

@ -239,8 +239,8 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog
structures. The system manages a pool of preallocated
watchdog structures to minimize dynamic allocations
CONFIG_DEV_FIFO_SIZE - Size, in bytes, of the buffer to allocated
for FIFO support
CONFIG_DEV_PIPE_SIZE - Size, in bytes, of the buffer to allocated
for pipe and FIFO support
TCP/IP and UDP support via uIP
CONFIG_NET - Enable or disable all network features

View File

@ -49,7 +49,7 @@
#include "pipe-common.h"
#if CONFIG_DEV_FIFO_SIZE > 0
#if CONFIG_DEV_PIPE_SIZE > 0
/****************************************************************************
* Definitions
@ -129,4 +129,4 @@ int mkfifo(FAR const char *pathname, mode_t mode)
}
return ret;
}
#endif /* CONFIG_DEV_FIFO_SIZE > 0 */
#endif /* CONFIG_DEV_PIPE_SIZE > 0 */

View File

@ -56,7 +56,7 @@
#include "pipe-common.h"
#if CONFIG_DEV_FIFO_SIZE > 0
#if CONFIG_DEV_PIPE_SIZE > 0
/****************************************************************************
* Definitions
@ -106,7 +106,7 @@ FAR struct pipe_dev_s *pipecommon_allocdev(void)
{
struct pipe_dev_s *dev;
/* Allocate a private structure to manage the FIFO */
/* Allocate a private structure to manage the pipe */
dev = (struct pipe_dev_s *)malloc(sizeof(struct pipe_dev_s));
if (dev)
@ -162,6 +162,8 @@ int pipecommon_open(FAR struct file *filep)
dev->s.d_nwriters++;
}
/* If opened for read-only, then wait for at least one writer on the pipe */
(void)sem_post(&dev->s.d_bfsem);
return OK;
}
@ -175,6 +177,7 @@ int pipecommon_close(FAR struct file *filep)
{
struct inode *inode = filep->f_inode;
struct pipe_dev_s *dev = inode->i_private;
int sval;
/* Some sanity checking */
#if CONFIG_DEBUG
@ -203,14 +206,16 @@ int pipecommon_close(FAR struct file *filep)
if ((filep->f_oflags & O_WROK) != 0)
{
/* If there are no longer any writers on the pipe, then notify any
* waiting readers that must return end-of-file.
/* If there are no longer any writers on the pipe, then notify all of the
* waiting readers that they must return end-of-file.
*/
if (--dev->s.d_nwriters <= 0 && dev->s.d_rdwaiters > 0)
if (--dev->s.d_nwriters <= 0)
{
dev->s.d_rdwaiters--;
sem_post(&dev->s.d_rdsem);
while (sem_getvalue(&dev->s.d_rdsem, &sval) == 0 && sval < 0)
{
sem_post(&dev->s.d_rdsem);
}
}
}
sem_post(&dev->s.d_bfsem);
@ -222,7 +227,7 @@ int pipecommon_close(FAR struct file *filep)
inode->i_private = NULL;
sem_post(&dev->s.d_bfsem);
/* Then free the fifo structure instance */
/* Then free the pipe structure instance */
pipecommon_freedev(dev);
}
@ -237,6 +242,7 @@ ssize_t pipecommon_read(FAR struct file *filep, FAR char *buffer, size_t len)
struct inode *inode = filep->f_inode;
struct pipe_dev_s *dev = inode->i_private;
ssize_t nread = 0;
int sval;
int ret;
/* Some sanity checking */
@ -254,7 +260,7 @@ ssize_t pipecommon_read(FAR struct file *filep, FAR char *buffer, size_t len)
return ERROR;
}
/* If the fifo is empty, then wait for something to be written to it */
/* If the pipe is empty, then wait for something to be written to it */
while (dev->s.d_wrndx == dev->s.d_rdndx)
{
@ -274,9 +280,8 @@ ssize_t pipecommon_read(FAR struct file *filep, FAR char *buffer, size_t len)
return 0;
}
/* Otherwise, wait for something to be written to the FIFO */
/* Otherwise, wait for something to be written to the pipe */
dev->s.d_rdwaiters++;
sched_lock();
sem_post(&dev->s.d_bfsem);
ret = sem_wait(&dev->s.d_rdsem);
@ -287,24 +292,23 @@ ssize_t pipecommon_read(FAR struct file *filep, FAR char *buffer, size_t len)
}
}
/* Then return whatever is available in the FIFO (which is at least one byte) */
/* Then return whatever is available in the pipe (which is at least one byte) */
nread = 0;
while (nread < len && dev->s.d_wrndx != dev->s.d_rdndx)
{
*buffer++ = dev->d_buffer[dev->s.d_rdndx];
if (++dev->s.d_rdndx >= CONFIG_DEV_FIFO_SIZE)
if (++dev->s.d_rdndx >= CONFIG_DEV_PIPE_SIZE)
{
dev->s.d_rdndx = 0;
}
nread++;
}
/* Notify any waiting writers that bytes have been removed from the buffer */
/* Notify all waiting writers that bytes have been removed from the buffer */
if (dev->s.d_nwrwaiters > 0)
while (sem_getvalue(&dev->s.d_wrsem, &sval) == 0 && sval < 0)
{
dev->s.d_nwrwaiters--;
sem_post(&dev->s.d_wrsem);
}
@ -322,6 +326,7 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, size_t
ssize_t nwritten = 0;
ssize_t last;
int nxtwrndx;
int sval;
/* Some sanity checking */
#if CONFIG_DEBUG
@ -346,7 +351,7 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, size_t
/* Calculate the write index AFTER the next byte is written */
nxtwrndx = dev->s.d_wrndx + 1;
if (nxtwrndx >= CONFIG_DEV_FIFO_SIZE)
if (nxtwrndx >= CONFIG_DEV_PIPE_SIZE)
{
nxtwrndx = 0;
}
@ -364,11 +369,10 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, size_t
if (++nwritten >= len)
{
/* Yes.. Notify the waiting readers that more data is available */
/* Yes.. Notify all of the waiting readers that more data is available */
if (dev->s.d_rdwaiters > 0)
while (sem_getvalue(&dev->s.d_rdsem, &sval) == 0 && sval < 0)
{
dev->s.d_rdwaiters--;
sem_post(&dev->s.d_rdsem);
}
@ -384,11 +388,10 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, size_t
if (last < nwritten)
{
/* Yes.. Notify the waiting readers that more data is available */
/* Yes.. Notify all of the waiting readers that more data is available */
if (dev->s.d_rdwaiters > 0)
while (sem_getvalue(&dev->s.d_rdsem, &sval) == 0 && sval < 0)
{
dev->s.d_rdwaiters--;
sem_post(&dev->s.d_rdsem);
}
}
@ -406,9 +409,8 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, size_t
return nwritten;
}
/* There is more to be written.. wait for data to be removed from the FIFO */
/* There is more to be written.. wait for data to be removed from the pipe */
dev->s.d_nwrwaiters++;
sched_lock();
sem_post(&dev->s.d_bfsem);
pipecommon_semtake(&dev->s.d_wrsem);
@ -418,4 +420,4 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, size_t
}
}
#endif /* CONFIG_DEV_FIFO_SIZE > 0 */
#endif /* CONFIG_DEV_PIPE_SIZE > 0 */

View File

@ -43,28 +43,28 @@
#include <nuttx/config.h>
#include <sys/types.h>
#ifndef CONFIG_DEV_FIFO_SIZE
# define CONFIG_DEV_FIFO_SIZE 1024
#ifndef CONFIG_DEV_PIPE_SIZE
# define CONFIG_DEV_PIPE_SIZE 1024
#endif
#if CONFIG_DEV_FIFO_SIZE > 0
#if CONFIG_DEV_PIPE_SIZE > 0
/****************************************************************************
* Definitions
****************************************************************************/
/* Maximum number of open's supported on FIFO */
/* Maximum number of open's supported on pipe */
#define CONFIG_DEV_FIFO_MAXUSER 255
#define CONFIG_DEV_PIPE_MAXUSER 255
/****************************************************************************
* Public Types
****************************************************************************/
/* Make the FIFO index as small as possible for the configured FIFO size */
/* Make the buffer index as small as possible for the configured pipe size */
#if CONFIG_DEV_FIFO_SIZE > 65535
#if CONFIG_DEV_PIPE_SIZE > 65535
typedef uint32 pipe_ndx_t; /* 32-bit index */
#elif CONFIG_DEV_FIFO_SIZE > 255
#elif CONFIG_DEV_PIPE_SIZE > 255
typedef uint16 pipe_ndx_t; /* 16-bit index */
#else
typedef ubyte pipe_ndx_t; /* 8-bit index */
@ -77,17 +77,15 @@ struct pipe_state_s
sem_t d_wrsem; /* Full buffer - Writer waits for data read */
pipe_ndx_t d_wrndx; /* Index in d_buffer to save next byte written */
pipe_ndx_t d_rdndx; /* Index in d_buffer to return the next byte read */
ubyte d_refs; /* References counts on FIFO (limited to 255) */
ubyte d_nwriters; /* Number of open counts for write access */
ubyte d_rdwaiters; /* Number of readers waiting for write data to empty buffer */
ubyte d_nwrwaiters; /* Number of writers wiating for data read out of full buffer */
ubyte d_refs; /* References counts on pipe (limited to 255) */
ubyte d_nwriters; /* Number of reference counts for write access */
ubyte d_pipeno; /* Pipe minor number */
};
struct pipe_dev_s
{
struct pipe_state_s s;
ubyte d_buffer[CONFIG_DEV_FIFO_SIZE];
ubyte d_buffer[CONFIG_DEV_PIPE_SIZE];
};
/****************************************************************************
@ -113,5 +111,5 @@ EXTERN ssize_t pipecommon_write(FAR struct file *, FAR const char *, size_t);
}
#endif
#endif /* CONFIG_DEV_FIFO_SIZE > 0 */
#endif /* CONFIG_DEV_PIPE_SIZE > 0 */
#endif /* __DRIVERS_PIPE_COMMON_H */

View File

@ -53,7 +53,7 @@
#include "pipe-common.h"
#if CONFIG_DEV_FIFO_SIZE > 0
#if CONFIG_DEV_PIPE_SIZE > 0
/****************************************************************************
* Definitions
@ -254,4 +254,4 @@ errout:
return ERROR;
}
#endif /* CONFIG_DEV_FIFO_SIZE > 0 */
#endif /* CONFIG_DEV_PIPE_SIZE > 0 */