Skip to content

Commit 817e4ee

Browse files
wangchdoxiaoxiang781216
authored andcommitted
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>
1 parent bc561c6 commit 817e4ee

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

sched/signal/sig_action.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@
6262

6363
static spinlock_t g_sigaction_spin;
6464

65-
#if CONFIG_SIG_PREALLOC_ACTIONS > 0
66-
static sigactq_t g_sigactions[CONFIG_SIG_PREALLOC_ACTIONS];
67-
static bool g_sigactions_used = false;
68-
#endif
69-
7065
/****************************************************************************
7166
* Private Functions
7267
****************************************************************************/
@@ -86,23 +81,6 @@ static void nxsig_alloc_actionblock(void)
8681
irqstate_t flags;
8782
int i;
8883

89-
/* Use pre-allocated instances only once */
90-
91-
#if CONFIG_SIG_PREALLOC_ACTIONS > 0
92-
flags = spin_lock_irqsave(&g_sigaction_spin);
93-
if (!g_sigactions_used)
94-
{
95-
for (i = 0; i < CONFIG_SIG_PREALLOC_ACTIONS; i++)
96-
{
97-
sq_addlast((FAR sq_entry_t *)(g_sigactions + i), &g_sigfreeaction);
98-
}
99-
100-
g_sigactions_used = true;
101-
}
102-
103-
spin_unlock_irqrestore(&g_sigaction_spin, flags);
104-
#endif
105-
10684
/* Allocate a block of signal actions */
10785

10886
sigact = kmm_malloc((sizeof(sigactq_t)) * CONFIG_SIG_ALLOC_ACTIONS);

sched/signal/sig_initialize.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ struct sigpool_s
5151
* Public Data
5252
****************************************************************************/
5353

54+
/* This is a pool of pre-allocated signal action structures buffers */
55+
56+
#if CONFIG_SIG_PREALLOC_ACTIONS > 0
57+
sigactq_t g_sigactions[CONFIG_SIG_PREALLOC_ACTIONS];
58+
#endif
59+
5460
/* The g_sigfreeaction data structure is a list of available signal
5561
* action structures.
5662
*/
@@ -94,6 +100,22 @@ static struct sigpool_s g_sigpool;
94100
* Private Functions
95101
****************************************************************************/
96102

103+
#if CONFIG_SIG_PREALLOC_ACTIONS > 0
104+
static void nxsig_init_signalactionblock(sq_queue_t *siglist,
105+
FAR sigactq_t *sigact,
106+
uint16_t nsigs)
107+
{
108+
int i;
109+
110+
for (i = 0; i < nsigs; i++)
111+
{
112+
sq_addlast((FAR sq_entry_t *)sigact++, siglist);
113+
}
114+
}
115+
#else
116+
# define nxsig_init_signalactionblock(x, y, z)
117+
#endif
118+
97119
/****************************************************************************
98120
* Name: nxsig_init_block
99121
*
@@ -168,6 +190,9 @@ void nxsig_initialize(void)
168190
sq_init(&g_sigpendingsignal);
169191
sq_init(&g_sigpendingirqsignal);
170192

193+
nxsig_init_signalactionblock(&g_sigfreeaction,
194+
g_sigactions,
195+
CONFIG_SIG_PREALLOC_ACTIONS);
171196
sigpool = nxsig_init_block(&g_sigpendingaction, sigpool,
172197
NUM_PENDING_ACTIONS, SIG_ALLOC_FIXED);
173198
sigpool = nxsig_init_block(&g_sigpendingirqaction, sigpool,

sched/signal/signal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ typedef struct sigq_s sigq_t;
116116
* Public Data
117117
****************************************************************************/
118118

119+
/* The g_sigactions data structure a pool of pre-allocated signal action
120+
* structures buffers structures.
121+
*/
122+
123+
extern sigactq_t g_sigactions[CONFIG_SIG_PREALLOC_ACTIONS];
124+
119125
/* The g_sigfreeaction data structure is a list of available signal action
120126
* structures.
121127
*/

0 commit comments

Comments
 (0)