nuttx/sched/signal/sig_initialize.c

172 lines
5.4 KiB
C
Raw Normal View History

/****************************************************************************
* sched/signal/sig_initialize.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <assert.h>
#include <nuttx/kmalloc.h>
#include <nuttx/queue.h>
#include <nuttx/trace.h>
#include "signal/signal.h"
/****************************************************************************
* Public Data
****************************************************************************/
/* The g_sigfreeaction data structure is a list of available signal
* action structures.
*/
sq_queue_t g_sigfreeaction;
/* The g_sigpendingaction data structure is a list of available pending
* signal action structures.
*/
sq_queue_t g_sigpendingaction;
/* The g_sigpendingirqaction is a list of available pending signal actions
* that are reserved for use by interrupt handlers.
*/
sq_queue_t g_sigpendingirqaction;
/* The g_sigpendingsignal data structure is a list of available pending
* signal structures.
*/
sq_queue_t g_sigpendingsignal;
/* The g_sigpendingirqsignal data structure is a list of available
* pending signal structures that are reserved for use by interrupt
* handlers.
*/
sq_queue_t g_sigpendingirqsignal;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nxsig_init_block
*
* Description:
* Initialize a block of pending signal actions and place them
* on the free list.
*
****************************************************************************/
static void *nxsig_init_block(sq_queue_t *siglist, FAR sigq_t *sigq,
uint16_t nsigs, uint8_t sigtype)
{
2015-10-08 03:59:14 +02:00
int i;
for (i = 0; i < nsigs; i++)
{
sigq->type = sigtype;
sq_addlast((FAR sq_entry_t *)sigq++, siglist);
}
return sigq;
}
/****************************************************************************
* Name: nxsig_init_pendingsignalblock
*
* Description:
* Initialize a block of pending signal structures and place them on
* the free list.
*
****************************************************************************/
static void *nxsig_init_pendingsignalblock(FAR sq_queue_t *siglist,
FAR sigpendq_t *sigpend,
uint16_t nsigs,
uint8_t sigtype)
{
int i;
for (i = 0; i < nsigs; i++)
{
sigpend->type = sigtype;
sq_addlast((FAR sq_entry_t *)sigpend++, siglist);
}
return sigpend;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_ This is analogous to similar renaming that was done previously for semaphores. Squashed commit of the following: sched/signal: Fix a few compile warnings introduced by naming changes. sched/signal: Rename all private, internal signl functions to use the nxsig_ prefix. sched/signal: Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces. sched/signal: Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces. sched/signal: Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces. sched/signal: Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces. sched/signal: Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces. sched/signal: Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces. sched/signal: Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 21:25:25 +02:00
* Name: nxsig_initialize
*
* Description:
* Perform one-time power-up initialization
*
****************************************************************************/
This change renames all internal, private NuttX signal-related functions to use the prefix nxsig_ so that they cannot be confused with application interfaces that begin, primarily, with sig_ This is analogous to similar renaming that was done previously for semaphores. Squashed commit of the following: sched/signal: Fix a few compile warnings introduced by naming changes. sched/signal: Rename all private, internal signl functions to use the nxsig_ prefix. sched/signal: Rename sig_removependingsignal, sig_unmaskpendingsignal, and sig_mqnotempty to nxsig_remove_pendingsignal, nxsig_unmask_pendingsignal, and nxsig_mqnotempty to make it clear that these are OS internal interfaces. sched/signal: Rename sig_findaction and sig_lowest to nxsig_find_action and nxsig_lowest to make it clear that these are OS internal interfaces. sched/signal: Rename sig_allocatepingsigaction and sig_deliver to nxsig_alloc_pendingsigaction and nxsig_deliver to make it clear that these are OS internal interfaces. sched/signal: Rename sig_cleanup, sig_release, sig_releasependingaction, and sig_releasependingsignal to nxsig_cleanup, nxsig_release, nxsig_release_pendingaction, and nxsig_release_pendingsignal to make it clear that these are OS internal interfaces. sched/signal: Rename sig_tcbdispatch and sig_dispatch to nxsig_tcbdispatch and nxsig_dispatch to make it clear that these are OS internal interfaces. sched/signal: Rename sig_releaseaction and sig_pendingset to nxsig_release_action and nxsig_pendingset to make it clear that these are OS internal interfaces. sched/signal: Rename sig_initialize and sig_allocateactionblock to nxsig_initialize and nxsig_alloc_actionblock to make it clear that these are OS internal interfaces.
2017-10-05 21:25:25 +02:00
void nxsig_initialize(void)
{
FAR void *sigpool;
sched_trace_begin();
/* Initialize free lists */
sq_init(&g_sigfreeaction);
sq_init(&g_sigpendingaction);
sq_init(&g_sigpendingirqaction);
sq_init(&g_sigpendingsignal);
sq_init(&g_sigpendingirqsignal);
/* Add a block of signal structures to each list */
sigpool =
kmm_malloc(sizeof(sigq_t) *
(NUM_PENDING_ACTIONS + CONFIG_SIG_PREALLOC_IRQ_ACTIONS)
+ sizeof(sigpendq_t) *
(NUM_SIGNALS_PENDING + CONFIG_SIG_PREALLOC_IRQ_ACTIONS));
DEBUGASSERT(sigpool != NULL);
sigpool = nxsig_init_block(&g_sigpendingaction, sigpool,
NUM_PENDING_ACTIONS, SIG_ALLOC_FIXED);
sigpool = nxsig_init_block(&g_sigpendingirqaction, sigpool,
CONFIG_SIG_PREALLOC_IRQ_ACTIONS,
SIG_ALLOC_IRQ);
sigpool = nxsig_init_pendingsignalblock(&g_sigpendingsignal, sigpool,
NUM_SIGNALS_PENDING,
SIG_ALLOC_FIXED);
sigpool = nxsig_init_pendingsignalblock(&g_sigpendingirqsignal, sigpool,
CONFIG_SIG_PREALLOC_IRQ_ACTIONS,
SIG_ALLOC_IRQ);
sched_trace_end();
}