From 2f55807acb79490f615255e3c933ca0447f61a09 Mon Sep 17 00:00:00 2001 From: ligd Date: Tue, 13 Jul 2021 21:56:29 +0800 Subject: [PATCH] sched/signal: add spinlock to g_sigfreeaction To avoid nxsig_alloc_action() & nxsig_release_action() competition Signed-off-by: ligd --- sched/signal/sig_action.c | 40 +++++++++++++++++++++++++++++++++++ sched/signal/sig_initialize.c | 35 ------------------------------ sched/signal/signal.h | 1 - 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/sched/signal/sig_action.c b/sched/signal/sig_action.c index 312d07ef09..dae2629c7d 100644 --- a/sched/signal/sig_action.c +++ b/sched/signal/sig_action.c @@ -42,6 +42,37 @@ * Private Functions ****************************************************************************/ +/**************************************************************************** + * Name: nxsig_alloc_actionblock + * + * Description: + * Allocate a block of signal actions and place them + * on the free list. + * + ****************************************************************************/ + +static void nxsig_alloc_actionblock(void) +{ + FAR sigactq_t *sigact; + irqstate_t flags; + int i; + + /* Allocate a block of signal actions */ + + sigact = kmm_malloc((sizeof(sigactq_t)) * NUM_SIGNAL_ACTIONS); + if (sigact != NULL) + { + flags = spin_lock_irqsave(NULL); + + for (i = 0; i < NUM_SIGNAL_ACTIONS; i++) + { + sq_addlast((FAR sq_entry_t *)sigact++, &g_sigfreeaction); + } + + spin_unlock_irqrestore(NULL, flags); + } +} + /**************************************************************************** * Name: nxsig_alloc_action * @@ -53,10 +84,13 @@ static FAR sigactq_t *nxsig_alloc_action(void) { FAR sigactq_t *sigact; + irqstate_t flags; /* Try to get the signal action structure from the free list */ + flags = spin_lock_irqsave(NULL); sigact = (FAR sigactq_t *)sq_remfirst(&g_sigfreeaction); + spin_unlock_irqrestore(NULL, flags); /* Check if we got one. */ @@ -68,7 +102,9 @@ static FAR sigactq_t *nxsig_alloc_action(void) /* And try again */ + flags = spin_lock_irqsave(NULL); sigact = (FAR sigactq_t *)sq_remfirst(&g_sigfreeaction); + spin_unlock_irqrestore(NULL, flags); DEBUGASSERT(sigact); } @@ -363,7 +399,11 @@ int sigaction(int signo, FAR const struct sigaction *act, void nxsig_release_action(FAR sigactq_t *sigact) { + irqstate_t flags; + /* Just put it back on the free list */ + flags = spin_lock_irqsave(NULL); sq_addlast((FAR sq_entry_t *)sigact, &g_sigfreeaction); + spin_unlock_irqrestore(NULL, flags); } diff --git a/sched/signal/sig_initialize.c b/sched/signal/sig_initialize.c index 34e7b082de..5b793889d8 100644 --- a/sched/signal/sig_initialize.c +++ b/sched/signal/sig_initialize.c @@ -71,12 +71,6 @@ sq_queue_t g_sigpendingirqsignal; * Private Data ****************************************************************************/ -/* g_sigactionalloc is a pointer to the start of the allocated blocks of - * signal actions. - */ - -static sigactq_t *g_sigactionalloc; - /* g_sigpendingactionalloc is a pointer to the start of the allocated * blocks of pending signal actions. */ @@ -230,32 +224,3 @@ void nxsig_initialize(void) SIG_ALLOC_IRQ); DEBUGASSERT(g_sigpendingirqsignalalloc != NULL); } - -/**************************************************************************** - * Name: nxsig_alloc_actionblock - * - * Description: - * Allocate a block of signal actions and place them - * on the free list. - * - ****************************************************************************/ - -void nxsig_alloc_actionblock(void) -{ - FAR sigactq_t *sigact; - int i; - - /* Allocate a block of signal actions */ - - g_sigactionalloc = - (FAR sigactq_t *)kmm_malloc((sizeof(sigactq_t)) * NUM_SIGNAL_ACTIONS); - - if (g_sigactionalloc != NULL) - { - sigact = g_sigactionalloc; - for (i = 0; i < NUM_SIGNAL_ACTIONS; i++) - { - sq_addlast((FAR sq_entry_t *)sigact++, &g_sigfreeaction); - } - } -} diff --git a/sched/signal/signal.h b/sched/signal/signal.h index 8fe4b53e83..b8a3f5e1f6 100644 --- a/sched/signal/signal.h +++ b/sched/signal/signal.h @@ -148,7 +148,6 @@ struct task_group_s; /* sig_initializee.c */ void weak_function nxsig_initialize(void); -void nxsig_alloc_actionblock(void); /* sig_action.c */