You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2021/12/09 02:55:35 UTC
[incubator-nuttx] branch master updated: sched/signal: add spinlock to g_sigfreeaction
This is an automated email from the ASF dual-hosted git repository.
masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 2f55807 sched/signal: add spinlock to g_sigfreeaction
2f55807 is described below
commit 2f55807acb79490f615255e3c933ca0447f61a09
Author: ligd <li...@xiaomi.com>
AuthorDate: Tue Jul 13 21:56:29 2021 +0800
sched/signal: add spinlock to g_sigfreeaction
To avoid nxsig_alloc_action() & nxsig_release_action() competition
Signed-off-by: ligd <li...@xiaomi.com>
---
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 312d07e..dae2629 100644
--- a/sched/signal/sig_action.c
+++ b/sched/signal/sig_action.c
@@ -43,6 +43,37 @@
****************************************************************************/
/****************************************************************************
+ * 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
*
* Description:
@@ -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 34e7b08..5b79388 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 8fe4b53..b8a3f5e 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 */