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

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

commit d9a442a859cfe88bc28729a4f609a8bc9ae61f2b
Author: Xiang Xiao <xiaoxi...@xiaomi.com>
AuthorDate: Sat Mar 12 04:04:08 2022 +0800

    mm/iob: Remove initialized static variable inside iob_initialize
    
    since it's impossible to call iob_initialize twice
    
    Signed-off-by: Xiang Xiao <xiaoxi...@xiaomi.com>
---
 mm/iob/iob_initialize.c | 66 +++++++++++++++++++------------------------------
 1 file changed, 26 insertions(+), 40 deletions(-)

diff --git a/mm/iob/iob_initialize.c b/mm/iob/iob_initialize.c
index bb6bae1..ea54a13 100644
--- a/mm/iob/iob_initialize.c
+++ b/mm/iob/iob_initialize.c
@@ -73,12 +73,19 @@ FAR struct iob_qentry_s *g_iob_qcommitted;
 
 /* Counting semaphores that tracks the number of free IOBs/qentries */
 
-sem_t g_iob_sem;            /* Counts free I/O buffers */
+sem_t g_iob_sem = SEM_INITIALIZER(CONFIG_IOB_NBUFFERS);
+
 #if CONFIG_IOB_THROTTLE > 0
-sem_t g_throttle_sem;       /* Counts available I/O buffers when throttled */
+/* Counts available I/O buffers when throttled */
+
+sem_t g_throttle_sem = SEM_INITIALIZER(CONFIG_IOB_NBUFFERS -
+                                       CONFIG_IOB_THROTTLE);
 #endif
+
 #if CONFIG_IOB_NCHAINS > 0
-sem_t g_qentry_sem;         /* Counts free I/O buffer queue containers */
+/* Counts free I/O buffer queue containers */
+
+sem_t g_qentry_sem = SEM_INITIALIZER(CONFIG_IOB_NCHAINS);
 #endif
 
 /****************************************************************************
@@ -95,54 +102,33 @@ sem_t g_qentry_sem;         /* Counts free I/O buffer 
queue containers */
 
 void iob_initialize(void)
 {
-  static bool initialized = false;
   int i;
 
-  /* Perform one-time initialization */
+  /* Add each I/O buffer to the free list */
 
-  if (!initialized)
+  for (i = 0; i < CONFIG_IOB_NBUFFERS; i++)
     {
-      /* Add each I/O buffer to the free list */
+      FAR struct iob_s *iob = &g_iob_pool[i];
 
-      for (i = 0; i < CONFIG_IOB_NBUFFERS; i++)
-        {
-          FAR struct iob_s *iob = &g_iob_pool[i];
+      /* Add the pre-allocate I/O buffer to the head of the free list */
 
-          /* Add the pre-allocate I/O buffer to the head of the free list */
-
-          iob->io_flink  = g_iob_freelist;
-          g_iob_freelist = iob;
-        }
-
-      g_iob_committed = NULL;
-
-      nxsem_init(&g_iob_sem, 0, CONFIG_IOB_NBUFFERS);
-#if CONFIG_IOB_THROTTLE > 0
-      nxsem_init(&g_throttle_sem,
-                 0,
-                 CONFIG_IOB_NBUFFERS - CONFIG_IOB_THROTTLE);
-#endif
+      iob->io_flink  = g_iob_freelist;
+      g_iob_freelist = iob;
+    }
 
 #if CONFIG_IOB_NCHAINS > 0
       /* Add each I/O buffer chain queue container to the free list */
 
-      for (i = 0; i < CONFIG_IOB_NCHAINS; i++)
-        {
-          FAR struct iob_qentry_s *iobq = &g_iob_qpool[i];
-
-          /* Add the pre-allocate buffer container to the head of the free
-           * list
-           */
-
-          iobq->qe_flink  = g_iob_freeqlist;
-          g_iob_freeqlist = iobq;
-        }
-
-      g_iob_qcommitted = NULL;
+  for (i = 0; i < CONFIG_IOB_NCHAINS; i++)
+    {
+      FAR struct iob_qentry_s *iobq = &g_iob_qpool[i];
 
-      nxsem_init(&g_qentry_sem, 0, CONFIG_IOB_NCHAINS);
-#endif
+      /* Add the pre-allocate buffer container to the head of the free
+       * list
+       */
 
-      initialized = true;
+      iobq->qe_flink  = g_iob_freeqlist;
+      g_iob_freeqlist = iobq;
     }
+#endif
 }

Reply via email to