sched/signal: add spinlock to g_sigfreeaction
To avoid nxsig_alloc_action() & nxsig_release_action() competition Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
parent
ae57492189
commit
2f55807acb
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user