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/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 63a0a544be sched/signal: merge allocate of signal pool
63a0a544be is described below

commit 63a0a544be01ab3443315044c37ca1fff08f36d6
Author: chao an <anc...@lixiang.com>
AuthorDate: Fri Mar 22 15:57:01 2024 +0800

    sched/signal: merge allocate of signal pool
    
    1. merge allocate of signal pool
    2. remove unnecessary static variables
    
    Signed-off-by: chao an <anc...@lixiang.com>
---
 sched/signal/sig_initialize.c | 135 ++++++++++++------------------------------
 1 file changed, 39 insertions(+), 96 deletions(-)

diff --git a/sched/signal/sig_initialize.c b/sched/signal/sig_initialize.c
index 12d7cec37f..3f9e2a1e67 100644
--- a/sched/signal/sig_initialize.c
+++ b/sched/signal/sig_initialize.c
@@ -68,111 +68,56 @@ sq_queue_t  g_sigpendingsignal;
 
 sq_queue_t  g_sigpendingirqsignal;
 
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/* g_sigpendingactionalloc is a pointer to the start of the allocated
- * blocks of pending signal actions.
- */
-
-static sigq_t     *g_sigpendingactionalloc;
-
-/* g_sigpendingirqactionalloc is a pointer to the start of the allocated
- * block of pending signal actions.
- */
-
-static sigq_t     *g_sigpendingirqactionalloc;
-
-/* g_sigpendingsignalalloc is a pointer to the start of the allocated
- * blocks of pending signals.
- */
-
-static sigpendq_t *g_sigpendingsignalalloc;
-
-/* g_sigpendingirqsignalalloc is a pointer to the start of the allocated
- * blocks of pending signals.
- */
-
-static sigpendq_t *g_sigpendingirqsignalalloc;
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-static sigq_t     *nxsig_alloc_block(sq_queue_t *siglist, uint16_t nsigs,
-                                     uint8_t sigtype);
-static sigpendq_t *nxsig_alloc_pendingsignalblock(sq_queue_t *siglist,
-                                                  uint16_t nsigs,
-                                                  uint8_t sigtype);
-
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: nxsig_alloc_block
+ * Name: nxsig_init_block
  *
  * Description:
- *   Allocate a block of pending signal actions and place them
+ *   Initialize a block of pending signal actions and place them
  *   on the free list.
  *
  ****************************************************************************/
 
-static FAR sigq_t *nxsig_alloc_block(sq_queue_t *siglist, uint16_t nsigs,
-                                     uint8_t sigtype)
+static void *nxsig_init_block(sq_queue_t *siglist, FAR sigq_t *sigq,
+                              uint16_t nsigs, uint8_t sigtype)
 {
-  FAR sigq_t *sigqalloc;
-  FAR sigq_t *sigq;
   int i;
 
-  /* Allocate a block of pending signal actions. */
-
-  sigqalloc = kmm_malloc(sizeof(sigq_t) * nsigs);
-  if (sigqalloc != NULL)
+  for (i = 0; i < nsigs; i++)
     {
-      sigq = sigqalloc;
-      for (i = 0; i < nsigs; i++)
-        {
-          sigq->type = sigtype;
-          sq_addlast((FAR sq_entry_t *)sigq++, siglist);
-        }
+      sigq->type = sigtype;
+      sq_addlast((FAR sq_entry_t *)sigq++, siglist);
     }
 
-  return sigqalloc;
+  return sigq;
 }
 
 /****************************************************************************
- * Name: nxsig_alloc_pendingsignalblock
+ * Name: nxsig_init_pendingsignalblock
  *
  * Description:
- *   Allocate a block of pending signal structures  and place them on
+ *   Initialize a block of pending signal structures  and place them on
  *   the free list.
  *
  ****************************************************************************/
 
-static sigpendq_t *nxsig_alloc_pendingsignalblock(sq_queue_t *siglist,
-                                                  uint16_t nsigs,
-                                                  uint8_t sigtype)
+static void *nxsig_init_pendingsignalblock(FAR sq_queue_t *siglist,
+                                           FAR sigpendq_t *sigpend,
+                                           uint16_t nsigs,
+                                           uint8_t sigtype)
 {
-  FAR sigpendq_t *sigpendalloc;
-  FAR sigpendq_t *sigpend;
   int i;
 
-  /* Allocate a block of pending signal structures  */
-
-  sigpendalloc = kmm_malloc(sizeof(sigpendq_t) * nsigs);
-  if (sigpendalloc != NULL)
+  for (i = 0; i < nsigs; i++)
     {
-      sigpend = sigpendalloc;
-      for (i = 0; i < nsigs; i++)
-        {
-          sigpend->type = sigtype;
-          sq_addlast((FAR sq_entry_t *)sigpend++, siglist);
-        }
+      sigpend->type = sigtype;
+      sq_addlast((FAR sq_entry_t *)sigpend++, siglist);
     }
 
-  return sigpendalloc;
+  return sigpend;
 }
 
 /****************************************************************************
@@ -189,6 +134,8 @@ static sigpendq_t 
*nxsig_alloc_pendingsignalblock(sq_queue_t *siglist,
 
 void nxsig_initialize(void)
 {
+  FAR void *sigpool;
+
   sched_trace_begin();
 
   /* Initialize free lists */
@@ -201,28 +148,24 @@ void nxsig_initialize(void)
 
   /* Add a block of signal structures to each list */
 
-  g_sigpendingactionalloc =
-    nxsig_alloc_block(&g_sigpendingaction,
-                      NUM_PENDING_ACTIONS,
-                      SIG_ALLOC_FIXED);
-  DEBUGASSERT(g_sigpendingactionalloc != NULL);
-
-  g_sigpendingirqactionalloc =
-    nxsig_alloc_block(&g_sigpendingirqaction,
-                      CONFIG_SIG_PREALLOC_IRQ_ACTIONS,
-                      SIG_ALLOC_IRQ);
-  DEBUGASSERT(g_sigpendingirqactionalloc != NULL);
-
-  g_sigpendingsignalalloc =
-    nxsig_alloc_pendingsignalblock(&g_sigpendingsignal,
-                                   NUM_SIGNALS_PENDING,
-                                   SIG_ALLOC_FIXED);
-  DEBUGASSERT(g_sigpendingsignalalloc != NULL);
-
-  g_sigpendingirqsignalalloc =
-    nxsig_alloc_pendingsignalblock(&g_sigpendingirqsignal,
-                                   CONFIG_SIG_PREALLOC_IRQ_ACTIONS,
-                                   SIG_ALLOC_IRQ);
-  DEBUGASSERT(g_sigpendingirqsignalalloc != NULL);
+  sigpool =
+    kmm_malloc(sizeof(sigq_t) *
+               (NUM_PENDING_ACTIONS + CONFIG_SIG_PREALLOC_IRQ_ACTIONS)
+               + sizeof(sigpendq_t) *
+                 (NUM_SIGNALS_PENDING + CONFIG_SIG_PREALLOC_IRQ_ACTIONS));
+
+  DEBUGASSERT(sigpool != NULL);
+
+  sigpool = nxsig_init_block(&g_sigpendingaction, sigpool,
+                             NUM_PENDING_ACTIONS, SIG_ALLOC_FIXED);
+  sigpool = nxsig_init_block(&g_sigpendingirqaction, sigpool,
+                             CONFIG_SIG_PREALLOC_IRQ_ACTIONS,
+                             SIG_ALLOC_IRQ);
+  sigpool = nxsig_init_pendingsignalblock(&g_sigpendingsignal, sigpool,
+                                          NUM_SIGNALS_PENDING,
+                                          SIG_ALLOC_FIXED);
+  sigpool = nxsig_init_pendingsignalblock(&g_sigpendingirqsignal, sigpool,
+                                          CONFIG_SIG_PREALLOC_IRQ_ACTIONS,
+                                          SIG_ALLOC_IRQ);
   sched_trace_end();
 }

Reply via email to