You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/02/07 04:05:52 UTC

[incubator-nuttx] branch master updated (0499979 -> 22f2269)

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from 0499979  sched: Disable pthread by default when DEFAULT_SMALL is enabled
     new 345d2ac  drivers/pipe: Add g_ prefix to pipe_fops and fifo_fops
     new 22f2269  drivers/pipe: Remove pipe from file system after open

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 drivers/pipes/fifo.c        |   4 +-
 drivers/pipes/pipe.c        | 119 ++++++++++++--------------------------------
 drivers/pipes/pipe_common.c |   3 --
 drivers/pipes/pipe_common.h |   1 -
 4 files changed, 35 insertions(+), 92 deletions(-)

[incubator-nuttx] 02/02: drivers/pipe: Remove pipe from file system after open

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 22f2269d6a7d3c8005ed943f34988c9de467d94a
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Feb 6 06:25:07 2022 +0800

    drivers/pipe: Remove pipe from file system after open
    
    to make the pipe as an anonymous object as soon as
    possible and simplify the life cycle management
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 drivers/pipes/pipe.c        | 117 ++++++++++++--------------------------------
 drivers/pipes/pipe_common.c |   3 --
 drivers/pipes/pipe_common.h |   1 -
 3 files changed, 32 insertions(+), 89 deletions(-)

diff --git a/drivers/pipes/pipe.c b/drivers/pipes/pipe.c
index 96599dd..d0cac63 100644
--- a/drivers/pipes/pipe.c
+++ b/drivers/pipes/pipe.c
@@ -40,12 +40,6 @@
 #if CONFIG_DEV_PIPE_SIZE > 0
 
 /****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define MAX_PIPES 32
-
-/****************************************************************************
  * Private Types
  ****************************************************************************/
 
@@ -68,14 +62,10 @@ static const struct file_operations g_pipe_fops =
   NULL,                /* seek */
   pipecommon_ioctl,    /* ioctl */
   pipecommon_poll      /* poll */
-#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
-  , pipecommon_unlink  /* unlink */
-#endif
 };
 
-static sem_t  g_pipesem       = SEM_INITIALIZER(1);
-static uint32_t g_pipeset     = 0;
-static uint32_t g_pipecreated = 0;
+static sem_t g_pipesem = SEM_INITIALIZER(1);
+static int   g_pipeno;
 
 /****************************************************************************
  * Private Functions
@@ -87,36 +77,22 @@ static uint32_t g_pipecreated = 0;
 
 static inline int pipe_allocate(void)
 {
-  int pipeno;
-  int ret = -ENFILE;
+  int ret;
 
-  for (pipeno = 0; pipeno < MAX_PIPES; pipeno++)
+  ret = nxsem_wait(&g_pipesem);
+  if (ret < 0)
     {
-      if ((g_pipeset & (1 << pipeno)) == 0)
-        {
-          g_pipeset |= (1 << pipeno);
-          ret = pipeno;
-          break;
-        }
+      return ret;
     }
 
-  return ret;
-}
-
-/****************************************************************************
- * Name: pipe_free
- ****************************************************************************/
-
-static inline void pipe_free(int pipeno)
-{
-  int ret;
-
-  ret = nxsem_wait(&g_pipesem);
-  if (ret == OK)
+  ret = g_pipeno++;
+  if (g_pipeno < 0)
     {
-      g_pipeset &= ~(1 << pipeno);
-      nxsem_post(&g_pipesem);
+      g_pipeno = 0;
     }
+
+  nxsem_post(&g_pipesem);
+  return ret;
 }
 
 /****************************************************************************
@@ -138,7 +114,7 @@ static int pipe_close(FAR struct file *filep)
     {
       /* Release the pipe when there are no further open references to it. */
 
-      pipe_free(dev->d_pipeno);
+      pipecommon_freedev(dev);
     }
 
   return ret;
@@ -155,69 +131,34 @@ static int pipe_register(size_t bufsize, int flags,
   int pipeno;
   int ret;
 
-  /* Get exclusive access to the pipe allocation data */
-
-  ret = nxsem_wait(&g_pipesem);
-  if (ret < 0)
-    {
-      goto errout;
-    }
-
   /* Allocate a minor number for the pipe device */
 
   pipeno = pipe_allocate();
   if (pipeno < 0)
     {
-      ret = pipeno;
-      goto errout_with_sem;
+      return pipeno;
     }
 
   /* Create a pathname to the pipe device */
 
   snprintf(devname, namesize, CONFIG_DEV_PIPE_VFS_PATH"/%d", pipeno);
 
-  /* Check if the pipe device has already been created */
+  /* Allocate and initialize a new device structure instance */
 
-  if ((g_pipecreated & (1 << pipeno)) == 0)
+  dev = pipecommon_allocdev(bufsize);
+  if (dev == NULL)
     {
-      /* No.. Allocate and initialize a new device structure instance */
-
-      dev = pipecommon_allocdev(bufsize);
-      if (!dev)
-        {
-          ret = -ENOMEM;
-          goto errout_with_pipe;
-        }
-
-      dev->d_pipeno = pipeno;
-
-      /* Register the pipe device */
-
-      ret = register_driver(devname, &g_pipe_fops, 0666, (FAR void *)dev);
-      if (ret != 0)
-        {
-          nxsem_post(&g_pipesem);
-          goto errout_with_dev;
-        }
-
-      /* Remember that we created this device */
-
-       g_pipecreated |= (1 << pipeno);
+      return -ENOMEM;
     }
 
-  nxsem_post(&g_pipesem);
-  return OK;
-
-errout_with_dev:
-  pipecommon_freedev(dev);
+  /* Register the pipe device */
 
-errout_with_pipe:
-  pipe_free(pipeno);
-
-errout_with_sem:
-  nxsem_post(&g_pipesem);
+  ret = register_driver(devname, &g_pipe_fops, 0666, (FAR void *)dev);
+  if (ret != 0)
+    {
+      pipecommon_freedev(dev);
+    }
 
-errout:
   return ret;
 }
 
@@ -251,7 +192,7 @@ errout:
 
 int file_pipe(FAR struct file *filep[2], size_t bufsize, int flags)
 {
-  char devname[16];
+  char devname[32];
   int ret;
 
   /* Register a new pipe device */
@@ -278,6 +219,9 @@ int file_pipe(FAR struct file *filep[2], size_t bufsize, int flags)
       goto errout_with_wrfd;
     }
 
+  /* Remove the pipe name from file system */
+
+  unregister_driver(devname);
   return OK;
 
 errout_with_wrfd:
@@ -290,7 +234,7 @@ errout_with_driver:
 
 int nx_pipe(int fd[2], size_t bufsize, int flags)
 {
-  char devname[16];
+  char devname[32];
   int ret;
 
   /* Register a new pipe device */
@@ -319,6 +263,9 @@ int nx_pipe(int fd[2], size_t bufsize, int flags)
       goto errout_with_wrfd;
     }
 
+  /* Remove the pipe name from file system */
+
+  unregister_driver(devname);
   return OK;
 
 errout_with_wrfd:
diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c
index 7a63907..9a90585 100644
--- a/drivers/pipes/pipe_common.c
+++ b/drivers/pipes/pipe_common.c
@@ -37,9 +37,6 @@
 #include <assert.h>
 #include <debug.h>
 
-#ifdef CONFIG_DEBUG_FEATURES
-#  include <nuttx/arch.h>
-#endif
 #include <nuttx/kmalloc.h>
 #include <nuttx/semaphore.h>
 #include <nuttx/fs/fs.h>
diff --git a/drivers/pipes/pipe_common.h b/drivers/pipes/pipe_common.h
index 1ccfc17..380a2bc 100644
--- a/drivers/pipes/pipe_common.h
+++ b/drivers/pipes/pipe_common.h
@@ -121,7 +121,6 @@ struct pipe_dev_s
   pipe_ndx_t d_bufsize;     /* allocated size of d_buffer in bytes */
   uint8_t    d_nwriters;    /* Number of reference counts for write access */
   uint8_t    d_nreaders;    /* Number of reference counts for read access */
-  uint8_t    d_pipeno;      /* Pipe minor number */
   uint8_t    d_flags;       /* See PIPE_FLAG_* definitions */
   uint8_t   *d_buffer;      /* Buffer allocated when device opened */
 

[incubator-nuttx] 01/02: drivers/pipe: Add g_ prefix to pipe_fops and fifo_fops

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 345d2ac2279ef0cdf55ea6008e168eb1c0977519
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Feb 6 00:03:15 2022 +0800

    drivers/pipe: Add g_ prefix to pipe_fops and fifo_fops
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 drivers/pipes/fifo.c | 4 ++--
 drivers/pipes/pipe.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/pipes/fifo.c b/drivers/pipes/fifo.c
index f629c6e..61010d3 100644
--- a/drivers/pipes/fifo.c
+++ b/drivers/pipes/fifo.c
@@ -39,7 +39,7 @@
  * Private Data
  ****************************************************************************/
 
-static const struct file_operations fifo_fops =
+static const struct file_operations g_fifo_fops =
 {
   pipecommon_open,     /* open */
   pipecommon_close,    /* close */
@@ -104,7 +104,7 @@ int nx_mkfifo(FAR const char *pathname, mode_t mode, size_t bufsize)
       return -ENOMEM;
     }
 
-  ret = register_driver(pathname, &fifo_fops, mode, (FAR void *)dev);
+  ret = register_driver(pathname, &g_fifo_fops, mode, (FAR void *)dev);
   if (ret != 0)
     {
       pipecommon_freedev(dev);
diff --git a/drivers/pipes/pipe.c b/drivers/pipes/pipe.c
index 14d0529..96599dd 100644
--- a/drivers/pipes/pipe.c
+++ b/drivers/pipes/pipe.c
@@ -59,7 +59,7 @@ static int pipe_close(FAR struct file *filep);
  * Private Data
  ****************************************************************************/
 
-static const struct file_operations pipe_fops =
+static const struct file_operations g_pipe_fops =
 {
   pipecommon_open,     /* open */
   pipe_close,          /* close */
@@ -193,7 +193,7 @@ static int pipe_register(size_t bufsize, int flags,
 
       /* Register the pipe device */
 
-      ret = register_driver(devname, &pipe_fops, 0666, (FAR void *)dev);
+      ret = register_driver(devname, &g_pipe_fops, 0666, (FAR void *)dev);
       if (ret != 0)
         {
           nxsem_post(&g_pipesem);