mirror of
https://github.com/apache/nuttx.git
synced 2025-12-06 17:23:49 +08:00
sched/signal: Initialize signal action pool during init phase
Initialize the signal action pool during the signal initialization phase to improve performance and reduce footprint. Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
This commit is contained in:
committed by
Xiang Xiao
parent
bc561c677a
commit
817e4ee354
@@ -62,11 +62,6 @@
|
||||
|
||||
static spinlock_t g_sigaction_spin;
|
||||
|
||||
#if CONFIG_SIG_PREALLOC_ACTIONS > 0
|
||||
static sigactq_t g_sigactions[CONFIG_SIG_PREALLOC_ACTIONS];
|
||||
static bool g_sigactions_used = false;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@@ -86,23 +81,6 @@ static void nxsig_alloc_actionblock(void)
|
||||
irqstate_t flags;
|
||||
int i;
|
||||
|
||||
/* Use pre-allocated instances only once */
|
||||
|
||||
#if CONFIG_SIG_PREALLOC_ACTIONS > 0
|
||||
flags = spin_lock_irqsave(&g_sigaction_spin);
|
||||
if (!g_sigactions_used)
|
||||
{
|
||||
for (i = 0; i < CONFIG_SIG_PREALLOC_ACTIONS; i++)
|
||||
{
|
||||
sq_addlast((FAR sq_entry_t *)(g_sigactions + i), &g_sigfreeaction);
|
||||
}
|
||||
|
||||
g_sigactions_used = true;
|
||||
}
|
||||
|
||||
spin_unlock_irqrestore(&g_sigaction_spin, flags);
|
||||
#endif
|
||||
|
||||
/* Allocate a block of signal actions */
|
||||
|
||||
sigact = kmm_malloc((sizeof(sigactq_t)) * CONFIG_SIG_ALLOC_ACTIONS);
|
||||
|
||||
@@ -51,6 +51,12 @@ struct sigpool_s
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* This is a pool of pre-allocated signal action structures buffers */
|
||||
|
||||
#if CONFIG_SIG_PREALLOC_ACTIONS > 0
|
||||
sigactq_t g_sigactions[CONFIG_SIG_PREALLOC_ACTIONS];
|
||||
#endif
|
||||
|
||||
/* The g_sigfreeaction data structure is a list of available signal
|
||||
* action structures.
|
||||
*/
|
||||
@@ -94,6 +100,22 @@ static struct sigpool_s g_sigpool;
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_SIG_PREALLOC_ACTIONS > 0
|
||||
static void nxsig_init_signalactionblock(sq_queue_t *siglist,
|
||||
FAR sigactq_t *sigact,
|
||||
uint16_t nsigs)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nsigs; i++)
|
||||
{
|
||||
sq_addlast((FAR sq_entry_t *)sigact++, siglist);
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define nxsig_init_signalactionblock(x, y, z)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxsig_init_block
|
||||
*
|
||||
@@ -168,6 +190,9 @@ void nxsig_initialize(void)
|
||||
sq_init(&g_sigpendingsignal);
|
||||
sq_init(&g_sigpendingirqsignal);
|
||||
|
||||
nxsig_init_signalactionblock(&g_sigfreeaction,
|
||||
g_sigactions,
|
||||
CONFIG_SIG_PREALLOC_ACTIONS);
|
||||
sigpool = nxsig_init_block(&g_sigpendingaction, sigpool,
|
||||
NUM_PENDING_ACTIONS, SIG_ALLOC_FIXED);
|
||||
sigpool = nxsig_init_block(&g_sigpendingirqaction, sigpool,
|
||||
|
||||
@@ -116,6 +116,12 @@ typedef struct sigq_s sigq_t;
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* The g_sigactions data structure a pool of pre-allocated signal action
|
||||
* structures buffers structures.
|
||||
*/
|
||||
|
||||
extern sigactq_t g_sigactions[CONFIG_SIG_PREALLOC_ACTIONS];
|
||||
|
||||
/* The g_sigfreeaction data structure is a list of available signal action
|
||||
* structures.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user