diff --git a/mm/iob/iob_initialize.c b/mm/iob/iob_initialize.c index bb6bae13b7..ea54a13a12 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]; + 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 - */ + /* 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; - - nxsem_init(&g_qentry_sem, 0, CONFIG_IOB_NCHAINS); -#endif - - initialized = true; + iobq->qe_flink = g_iob_freeqlist; + g_iob_freeqlist = iobq; } +#endif }