summaryrefslogtreecommitdiff
path: root/nuttx/drivers
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-19 18:43:50 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-19 18:43:50 +0000
commitd8c1d769c45dde09573ea6ba3f968491cc5e68b2 (patch)
tree6a6105e2401ec7e9eb4e590c49c3121b2c4b82ae /nuttx/drivers
parentb62fb5c894ea28ccc83c5760605f5322bf38f971 (diff)
downloadpx4-nuttx-d8c1d769c45dde09573ea6ba3f968491cc5e68b2.tar.gz
px4-nuttx-d8c1d769c45dde09573ea6ba3f968491cc5e68b2.tar.bz2
px4-nuttx-d8c1d769c45dde09573ea6ba3f968491cc5e68b2.zip
Move poll save area back into struct pollfd (as it was
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1288 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/drivers')
-rw-r--r--nuttx/drivers/dev_null.c8
-rw-r--r--nuttx/drivers/dev_zero.c8
-rw-r--r--nuttx/drivers/pipe_common.c82
-rw-r--r--nuttx/drivers/pipe_common.h3
-rw-r--r--nuttx/drivers/serial.c80
5 files changed, 111 insertions, 70 deletions
diff --git a/nuttx/drivers/dev_null.c b/nuttx/drivers/dev_null.c
index a5e7d95ce..a8a8bb01c 100644
--- a/nuttx/drivers/dev_null.c
+++ b/nuttx/drivers/dev_null.c
@@ -56,7 +56,8 @@
static ssize_t devnull_read(FAR struct file *, FAR char *, size_t);
static ssize_t devnull_write(FAR struct file *, FAR const char *, size_t);
#ifndef CONFIG_DISABLE_POLL
-static int devnull_poll(FAR struct file *filp, FAR struct pollfd *fds);
+static int devnull_poll(FAR struct file *filp, FAR struct pollfd *fds,
+ boolean setup);
#endif
/****************************************************************************
@@ -103,9 +104,10 @@ static ssize_t devnull_write(FAR struct file *filp, FAR const char *buffer, size
****************************************************************************/
#ifndef CONFIG_DISABLE_POLL
-static int devnull_poll(FAR struct file *filp, FAR struct pollfd *fds)
+static int devnull_poll(FAR struct file *filp, FAR struct pollfd *fds,
+ boolean setup)
{
- if (fds)
+ if (setup)
{
fds->revents |= (fds->events & (POLLIN|POLLOUT));
if (fds->revents != 0)
diff --git a/nuttx/drivers/dev_zero.c b/nuttx/drivers/dev_zero.c
index 08815ace5..fff88fd8d 100644
--- a/nuttx/drivers/dev_zero.c
+++ b/nuttx/drivers/dev_zero.c
@@ -56,7 +56,8 @@
static ssize_t devzero_read(FAR struct file *, FAR char *, size_t);
static ssize_t devzero_write(FAR struct file *, FAR const char *, size_t);
#ifndef CONFIG_DISABLE_POLL
-static int devzero_poll(FAR struct file *filp, FAR struct pollfd *fds);
+static int devzero_poll(FAR struct file *filp, FAR struct pollfd *fds,
+ boolean setup);
#endif
/****************************************************************************
@@ -104,9 +105,10 @@ static ssize_t devzero_write(FAR struct file *filp, FAR const char *buffer, size
****************************************************************************/
#ifndef CONFIG_DISABLE_POLL
-static int devzero_poll(FAR struct file *filp, FAR struct pollfd *fds)
+static int devzero_poll(FAR struct file *filp, FAR struct pollfd *fds,
+ boolean setup)
{
- if (fds)
+ if (setup)
{
fds->revents |= (fds->events & (POLLIN|POLLOUT));
if (fds->revents != 0)
diff --git a/nuttx/drivers/pipe_common.c b/nuttx/drivers/pipe_common.c
index cede17ae1..434501559 100644
--- a/nuttx/drivers/pipe_common.c
+++ b/nuttx/drivers/pipe_common.c
@@ -197,10 +197,6 @@ int pipecommon_open(FAR struct file *filep)
}
}
- /* There is no, file-specific private data (at least not yet) */
-
- filep->f_priv = NULL;
-
/* Increment the reference count on the pipe instance */
dev->d_refs++;
@@ -517,58 +513,58 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, size_t
****************************************************************************/
#ifndef CONFIG_DISABLE_POLL
-int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds)
+int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds,
+ boolean setup)
{
FAR struct inode *inode = filep->f_inode;
FAR struct pipe_dev_s *dev = inode->i_private;
pollevent_t eventset;
pipe_ndx_t nbytes;
+ int ret = OK;
int i;
/* Some sanity checking */
+
#if CONFIG_DEBUG
- if (!dev)
+ if (!dev || !fds)
{
return -ENODEV;
}
#endif
- /* Find an available slot for the poll structure reference */
+ /* Are we setting up the poll? Or tearing it down? */
pipecommon_semtake(&dev->d_bfsem);
- for (i = 0; i < CONFIG_DEV_PIPE_NPOLLWAITERS; i++)
+ if (setup)
{
- /* Find the slot with the value equal to filep->f_priv. If there
- * is no previously installed poll structure, then f_priv will
- * be NULL and we will find the first unused slot. If f_priv is
- * is non-NULL, then we will find the slot that was used for the
- * previous setup.
+ /* This is a request to set up the poll. Find an available
+ * slot for the poll structure reference
*/
- if (dev->d_fds[i] == filep->f_priv)
+ for (i = 0; i < CONFIG_DEV_PIPE_NPOLLWAITERS; i++)
{
- dev->d_fds[i] = fds;
- break;
- }
- }
+ /* Find an available slot */
- if (i >= CONFIG_DEV_PIPE_NPOLLWAITERS)
- {
- DEBUGASSERT(fds != NULL);
- return -EBUSY;
- }
-
- /* Set or clear the poll event structure reference in the 'struct file'
- * private data.
- */
+ if (!dev->d_fds[i])
+ {
+ /* Bind the poll structure and this slot */
- filep->f_priv = fds;
+ dev->d_fds[i] = fds;
+ fds->private = &dev->d_fds[i];
+ break;
+ }
+ }
- /* Check if we should immediately notify on any of the requested events */
+ if (i >= CONFIG_DEV_PIPE_NPOLLWAITERS)
+ {
+ fds->private = NULL;
+ ret = -EBUSY;
+ goto errout;
+ }
- if (fds)
- {
- /* Determine how many bytes are in the buffer */
+ /* Should immediately notify on any of the requested events?
+ * First, determine how many bytes are in the buffer
+ */
if (dev->d_wrndx >= dev->d_rdndx)
{
@@ -599,9 +595,29 @@ int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds)
pipecommon_pollnotify(dev, eventset);
}
}
+ else
+ {
+ /* This is a request to tear down the poll. */
+
+ struct pollfd **slot = (struct pollfd **)fds->private;
+
+#ifdef CONFIG_DEBUG
+ if (!slot)
+ {
+ ret = -EIO;
+ goto errout;
+ }
+#endif
+
+ /* Remove all memory of the poll setup */
+
+ *slot = NULL;
+ fds->private = NULL;
+ }
+errout:
sem_post(&dev->d_bfsem);
- return OK;
+ return ret;
}
#endif
diff --git a/nuttx/drivers/pipe_common.h b/nuttx/drivers/pipe_common.h
index 05edd9ca2..56fa4865b 100644
--- a/nuttx/drivers/pipe_common.h
+++ b/nuttx/drivers/pipe_common.h
@@ -123,7 +123,8 @@ EXTERN int pipecommon_close(FAR struct file *filep);
EXTERN ssize_t pipecommon_read(FAR struct file *, FAR char *, size_t);
EXTERN ssize_t pipecommon_write(FAR struct file *, FAR const char *, size_t);
#ifndef CONFIG_DISABLE_POLL
-EXTERN int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds);
+EXTERN int pipecommon_poll(FAR struct file *filep, FAR struct pollfd *fds,
+ boolean setup);
#endif
#undef EXTERN
diff --git a/nuttx/drivers/serial.c b/nuttx/drivers/serial.c
index 4e409fa06..ddc7338bc 100644
--- a/nuttx/drivers/serial.c
+++ b/nuttx/drivers/serial.c
@@ -79,7 +79,7 @@ static ssize_t uart_read(FAR struct file *filep, FAR char *buffer, size_t buflen
static ssize_t uart_write(FAR struct file *filep, FAR const char *buffer, size_t buflen);
static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
#ifndef CONFIG_DISABLE_POLL
-static int uart_poll(FAR struct file *filep, FAR struct pollfd *fds);
+static int uart_poll(FAR struct file *filep, FAR struct pollfd *fds, boolean setup);
#endif
/************************************************************************************
@@ -400,58 +400,57 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
****************************************************************************/
#ifndef CONFIG_DISABLE_POLL
-int uart_poll(FAR struct file *filep, FAR struct pollfd *fds)
+int uart_poll(FAR struct file *filep, FAR struct pollfd *fds, boolean setup)
{
FAR struct inode *inode = filep->f_inode;
FAR uart_dev_t *dev = inode->i_private;
pollevent_t eventset;
int ndx;
+ int ret = OK;
int i;
/* Some sanity checking */
+
#if CONFIG_DEBUG
- if (!dev)
+ if (!dev || !fds)
{
return -ENODEV;
}
#endif
- /* Find an available slot for the poll structure reference */
+ /* Are we setting up the poll? Or tearing it down? */
uart_takesem(&dev->pollsem);
- for (i = 0; i < CONFIG_DEV_CONSOLE_NPOLLWAITERS; i++)
+ if (setup)
{
- /* Find the slot with the value equal to filep->f_priv. If there
- * is no previously installed poll structure, then f_priv will
- * be NULL and we will find the first unused slot. If f_priv is
- * is non-NULL, then we will find the slot that was used for the
- * previous setup.
+ /* This is a request to set up the poll. Find an available
+ * slot for the poll structure reference
*/
- if (dev->fds[i] == filep->f_priv)
+ for (i = 0; i < CONFIG_DEV_CONSOLE_NPOLLWAITERS; i++)
{
- dev->fds[i] = fds;
- break;
- }
- }
-
- if (i >= CONFIG_DEV_CONSOLE_NPOLLWAITERS)
- {
- DEBUGASSERT(fds != NULL);
- return -EBUSY;
- }
+ /* Find an available slot */
- /* Set or clear the poll event structure reference in the 'struct file'
- * private data.
- */
+ if (!dev->fds[i])
+ {
+ /* Bind the poll structure and this slot */
- filep->f_priv = fds;
+ dev->fds[i] = fds;
+ fds->private = &dev->fds[i];
+ break;
+ }
+ }
- /* Check if we should immediately notify on any of the requested events */
+ if (i >= CONFIG_DEV_CONSOLE_NPOLLWAITERS)
+ {
+ fds->private = NULL;
+ ret = -EBUSY;
+ goto errout;
+ }
- if (fds)
- {
- /* Check if the xmit buffer is full. */
+ /* Should immediately notify on any of the requested events?
+ * First, check if the xmit buffer is full.
+ */
eventset = 0;
@@ -480,10 +479,31 @@ int uart_poll(FAR struct file *filep, FAR struct pollfd *fds)
{
uart_pollnotify(dev, eventset);
}
+
+ }
+ else if (fds->private)
+ {
+ /* This is a request to tear down the poll. */
+
+ struct pollfd **slot = (struct pollfd **)fds->private;
+
+#ifdef CONFIG_DEBUG
+ if (!slot)
+ {
+ ret = -EIO;
+ goto errout;
+ }
+#endif
+
+ /* Remove all memory of the poll setup */
+
+ *slot = NULL;
+ fds->private = NULL;
}
+errout:
uart_givesem(&dev->pollsem);
- return OK;
+ return ret;
}
#endif