2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2014-08-08 20:55:02 +02:00
|
|
|
* sched/signal/sig_timedwait.c
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2017-02-24 17:07:23 +01:00
|
|
|
* Copyright (C) 2007-2009, 2012-2017 Gregory Nutt. All rights reserved.
|
2012-05-30 17:36:46 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
2008-01-31 18:59:22 +01:00
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
2007-02-18 00:21:28 +01:00
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-12-14 19:39:29 +01:00
|
|
|
#include <nuttx/config.h>
|
2012-12-24 18:49:58 +01:00
|
|
|
#include <nuttx/compiler.h>
|
2009-12-14 19:39:29 +01:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2007-02-21 22:55:16 +01:00
|
|
|
#include <string.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <signal.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <sched.h>
|
2012-05-30 17:36:46 +02:00
|
|
|
#include <errno.h>
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
#include <nuttx/irq.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <nuttx/arch.h>
|
2014-08-21 19:16:55 +02:00
|
|
|
#include <nuttx/wdog.h>
|
2017-10-06 16:28:20 +02:00
|
|
|
#include <nuttx/signal.h>
|
2016-12-10 16:08:26 +01:00
|
|
|
#include <nuttx/cancelpt.h>
|
2012-05-30 17:36:46 +02:00
|
|
|
|
2014-08-09 01:53:55 +02:00
|
|
|
#include "sched/sched.h"
|
2014-08-08 20:44:44 +02:00
|
|
|
#include "signal/signal.h"
|
2014-08-08 22:43:02 +02:00
|
|
|
#include "clock/clock.h"
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2012-05-30 17:36:46 +02:00
|
|
|
* Pre-processor Definitions
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-10-12 16:55:19 +02:00
|
|
|
/* These are special values of si_signo that mean that either the wait was
|
|
|
|
* awakened with a timeout, or the wait was canceled... not the receipt of a
|
|
|
|
* signal.
|
2012-05-30 17:36:46 +02:00
|
|
|
*/
|
|
|
|
|
2017-10-12 16:55:19 +02:00
|
|
|
#define SIG_CANCEL_TIMEOUT 0xfe
|
|
|
|
#define SIG_WAIT_TIMEOUT 0xff
|
2012-05-30 17:36:46 +02:00
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2014-04-25 20:38:56 +02:00
|
|
|
* Private Functions
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
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_timeout
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2017-02-24 17:07:23 +01:00
|
|
|
* A timeout elapsed while waiting for signals to be queued.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function executes in the context of the timer interrupt handler.
|
|
|
|
* Local interrupts are assumed to be disabled on entry.
|
2008-01-31 18:59:22 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
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
|
|
|
static void nxsig_timeout(int argc, wdparm_t itcb)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2017-02-24 17:07:23 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
irqstate_t flags;
|
|
|
|
#endif
|
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/* On many small machines, pointers are encoded and cannot be simply cast
|
2015-10-08 03:59:14 +02:00
|
|
|
* from uint32_t to struct tcb_s *. The following union works around this
|
2008-01-31 18:59:22 +01:00
|
|
|
* (see wdogparm_t). This odd logic could be conditioned on
|
|
|
|
* CONFIG_CAN_CAST_POINTERS, but it is not too bad in any case.
|
2007-02-21 22:55:16 +01:00
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2007-02-21 22:55:16 +01:00
|
|
|
union
|
2017-08-15 01:19:27 +02:00
|
|
|
{
|
|
|
|
FAR struct tcb_s *wtcb;
|
|
|
|
wdparm_t itcb;
|
|
|
|
} u;
|
2007-02-21 22:55:16 +01:00
|
|
|
|
2013-04-25 23:19:59 +02:00
|
|
|
u.itcb = itcb;
|
2017-10-12 16:55:19 +02:00
|
|
|
DEBUGASSERT(u.wtcb);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-02-24 17:07:23 +01:00
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
/* We must be in a critical section in order to call up_unblock_task()
|
|
|
|
* below. If we are running on a single CPU architecture, then we know
|
|
|
|
* interrupts a disabled an there is no need to explicitly call
|
|
|
|
* enter_critical_section(). However, in the SMP case,
|
|
|
|
* enter_critical_section() does much more than just disable interrupts on
|
|
|
|
* the local CPU; it also manages spinlocks to assure the stability of the
|
|
|
|
* TCB that we are manipulating.
|
|
|
|
*/
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* There may be a race condition -- make sure the task is
|
|
|
|
* still waiting for a signal
|
|
|
|
*/
|
|
|
|
|
2007-02-21 22:55:16 +01:00
|
|
|
if (u.wtcb->task_state == TSTATE_WAIT_SIG)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2012-05-30 17:36:46 +02:00
|
|
|
u.wtcb->sigunbinfo.si_signo = SIG_WAIT_TIMEOUT;
|
2008-01-31 18:59:22 +01:00
|
|
|
u.wtcb->sigunbinfo.si_code = SI_TIMER;
|
2015-08-14 18:10:32 +02:00
|
|
|
u.wtcb->sigunbinfo.si_errno = ETIMEDOUT;
|
2007-02-21 22:55:16 +01:00
|
|
|
u.wtcb->sigunbinfo.si_value.sival_int = 0;
|
2013-01-12 20:58:45 +01:00
|
|
|
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
|
|
u.wtcb->sigunbinfo.si_pid = 0; /* Not applicable */
|
|
|
|
u.wtcb->sigunbinfo.si_status = OK;
|
|
|
|
#endif
|
2007-02-21 22:55:16 +01:00
|
|
|
up_unblock_task(u.wtcb);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2017-02-24 17:07:23 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
leave_critical_section(flags);
|
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Functions
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-10-12 16:55:19 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxsig_wait_irq
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* An error event has occurred and the signal wait must be terminated with
|
|
|
|
* an error.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_CANCELLATION_POINTS
|
|
|
|
void nxsig_wait_irq(FAR struct tcb_s *wtcb, int errcode)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* We must be in a critical section in order to call up_unblock_task()
|
|
|
|
* below. If we are running on a single CPU architecture, then we know
|
|
|
|
* interrupts a disabled an there is no need to explicitly call
|
|
|
|
* enter_critical_section(). However, in the SMP case,
|
|
|
|
* enter_critical_section() does much more than just disable interrupts on
|
|
|
|
* the local CPU; it also manages spinlocks to assure the stability of the
|
|
|
|
* TCB that we are manipulating.
|
|
|
|
*/
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* There may be a race condition -- make sure the task is
|
|
|
|
* still waiting for a signal
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (wtcb->task_state == TSTATE_WAIT_SIG)
|
|
|
|
{
|
|
|
|
wtcb->sigunbinfo.si_signo = SIG_CANCEL_TIMEOUT;
|
|
|
|
wtcb->sigunbinfo.si_code = SI_USER;
|
|
|
|
wtcb->sigunbinfo.si_errno = errcode;
|
|
|
|
wtcb->sigunbinfo.si_value.sival_int = 0;
|
|
|
|
#ifdef CONFIG_SCHED_HAVE_PARENT
|
|
|
|
wtcb->sigunbinfo.si_pid = 0; /* Not applicable */
|
|
|
|
wtcb->sigunbinfo.si_status = OK;
|
|
|
|
#endif
|
|
|
|
up_unblock_task(wtcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
leave_critical_section(flags);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_CANCELLATION_POINTS */
|
|
|
|
|
2008-01-31 18:59:22 +01:00
|
|
|
/****************************************************************************
|
2017-10-06 16:28:20 +02:00
|
|
|
* Name: nxsig_timedwait
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2008-01-31 18:59:22 +01:00
|
|
|
* This function selects the pending signal set specified by the argument
|
|
|
|
* set. If multiple signals are pending in set, it will remove and return
|
|
|
|
* the lowest numbered one. If no signals in set are pending at the time
|
|
|
|
* of the call, the calling process will be suspended until one of the
|
|
|
|
* signals in set becomes pending, OR until the process is interrupted by
|
|
|
|
* an unblocked signal, OR until the time interval specified by timeout
|
|
|
|
* (if any), has expired. If timeout is NULL, then the timeout interval
|
|
|
|
* is forever.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
* If the info argument is non-NULL, the selected signal number is stored
|
2014-04-25 20:38:56 +02:00
|
|
|
* in the si_signo member and the cause of the signal is store din the
|
|
|
|
* si_code member. The content of si_value is only meaningful if the
|
2017-10-07 18:57:09 +02:00
|
|
|
* signal was generated by sigqueue() (or nxsig_queue).
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2017-10-06 16:28:20 +02:00
|
|
|
* This is an internal OS interface. It is functionally equivalent to
|
|
|
|
* sigtimedwait() except that:
|
|
|
|
*
|
|
|
|
* - It is not a cancellaction point, and
|
|
|
|
* - It does not modify the errno value.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-03-02 13:39:05 +01:00
|
|
|
* set - The pending signal set.
|
|
|
|
* info - The returned value (may be NULL).
|
|
|
|
* timeout - The amount of time to wait (may be NULL)
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-10-06 16:28:20 +02:00
|
|
|
* This is an internal OS interface and should not be used by applications.
|
|
|
|
* It follows the NuttX internal error return policy: Zero (OK) is
|
|
|
|
* returned on success. A negated errno value is returned on failure.
|
2012-05-30 17:36:46 +02:00
|
|
|
*
|
|
|
|
* EAGAIN - No signal specified by set was generated within the specified
|
|
|
|
* timeout period.
|
|
|
|
* EINTR - The wait was interrupted by an unblocked, caught signal.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-01-31 18:59:22 +01:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-10-06 16:28:20 +02:00
|
|
|
int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info,
|
|
|
|
FAR const struct timespec *timeout)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2016-02-07 00:44:41 +01:00
|
|
|
FAR struct tcb_s *rtcb = this_task();
|
2013-02-04 19:46:28 +01:00
|
|
|
sigset_t intersection;
|
2007-02-27 22:17:21 +01:00
|
|
|
FAR sigpendq_t *sigpend;
|
2016-02-14 15:17:46 +01:00
|
|
|
irqstate_t flags;
|
2013-02-04 19:46:28 +01:00
|
|
|
int32_t waitticks;
|
2017-10-06 16:28:20 +02:00
|
|
|
int ret;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-10-12 17:53:17 +02:00
|
|
|
DEBUGASSERT(set != NULL && rtcb->waitdog == NULL);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Several operations must be performed below: We must determine if any
|
|
|
|
* signal is pending and, if not, wait for the signal. Since signals can
|
|
|
|
* be posted from the interrupt level, there is a race condition that
|
|
|
|
* can only be eliminated by disabling interrupts!
|
|
|
|
*/
|
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
flags = enter_critical_section();
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Check if there is a pending signal corresponding to one of the
|
|
|
|
* signals in the pending signal set argument.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
intersection = *set & nxsig_pendingset(rtcb);
|
2007-02-18 00:21:28 +01:00
|
|
|
if (intersection != NULL_SIGNAL_SET)
|
|
|
|
{
|
|
|
|
/* One or more of the signals in intersections is sufficient to cause
|
|
|
|
* us to not wait. Pick the lowest numbered signal and mark it not
|
|
|
|
* pending.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
sigpend = nxsig_remove_pendingsignal(rtcb, nxsig_lowest(&intersection));
|
2017-10-06 16:28:20 +02:00
|
|
|
DEBUGASSERT(sigpend);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Return the signal info to the caller if so requested */
|
|
|
|
|
2017-03-02 13:39:05 +01:00
|
|
|
if (info != NULL)
|
2007-02-21 22:55:16 +01:00
|
|
|
{
|
|
|
|
memcpy(info, &sigpend->info, sizeof(struct siginfo));
|
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-07-27 20:32:47 +02:00
|
|
|
/* The return value is the number of the signal that awakened us */
|
|
|
|
|
|
|
|
ret = sigpend->info.si_signo;
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Then dispose of the pending signal structure properly */
|
|
|
|
|
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
|
|
|
nxsig_release_pendingsignal(sigpend);
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We will have to wait for a signal to be posted to this task. */
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2017-10-12 17:53:17 +02:00
|
|
|
#ifdef CONFIG_CANCELLATION_POINTS
|
|
|
|
/* nxsig_timedwait() is not a cancellation point, but it may be called
|
|
|
|
* from a cancellation point. So if a cancellation is pending, we
|
|
|
|
* must exit immediately without waiting.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (check_cancellation_point())
|
|
|
|
{
|
|
|
|
/* If there is a pending cancellation, then do not perform
|
|
|
|
* the wait. Exit now with ECANCELED.
|
|
|
|
*/
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
return -ECANCELED;
|
|
|
|
}
|
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Save the set of pending signals to wait for */
|
|
|
|
|
|
|
|
rtcb->sigwaitmask = *set;
|
|
|
|
|
|
|
|
/* Check if we should wait for the timeout */
|
|
|
|
|
2017-03-02 13:39:05 +01:00
|
|
|
if (timeout != NULL)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2012-12-24 15:31:02 +01:00
|
|
|
/* Convert the timespec to system clock ticks, making sure that
|
2014-04-25 20:38:56 +02:00
|
|
|
* the resulting delay is greater than or equal to the requested
|
2012-12-24 15:31:02 +01:00
|
|
|
* time in nanoseconds.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-12-24 15:31:02 +01:00
|
|
|
#ifdef CONFIG_HAVE_LONG_LONG
|
2012-12-24 18:49:58 +01:00
|
|
|
uint64_t waitticks64 = ((uint64_t)timeout->tv_sec * NSEC_PER_SEC +
|
|
|
|
(uint64_t)timeout->tv_nsec + NSEC_PER_TICK - 1) /
|
2017-08-15 01:19:27 +02:00
|
|
|
NSEC_PER_TICK;
|
2012-12-24 15:31:02 +01:00
|
|
|
DEBUGASSERT(waitticks64 <= UINT32_MAX);
|
|
|
|
waitticks = (uint32_t)waitticks64;
|
|
|
|
#else
|
|
|
|
uint32_t waitmsec;
|
|
|
|
|
|
|
|
DEBUGASSERT(timeout->tv_sec < UINT32_MAX / MSEC_PER_SEC);
|
|
|
|
waitmsec = timeout->tv_sec * MSEC_PER_SEC +
|
2017-08-15 01:19:27 +02:00
|
|
|
(timeout->tv_nsec + NSEC_PER_MSEC - 1) / NSEC_PER_MSEC;
|
2014-08-08 02:00:38 +02:00
|
|
|
waitticks = MSEC2TICK(waitmsec);
|
2012-12-24 15:31:02 +01:00
|
|
|
#endif
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Create a watchdog */
|
|
|
|
|
2013-02-06 16:43:28 +01:00
|
|
|
rtcb->waitdog = wd_create();
|
2014-04-22 03:16:12 +02:00
|
|
|
DEBUGASSERT(rtcb->waitdog);
|
|
|
|
|
2013-02-06 16:43:28 +01:00
|
|
|
if (rtcb->waitdog)
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2014-03-21 18:22:50 +01:00
|
|
|
/* This little bit of nonsense is necessary for some
|
2009-12-14 19:39:29 +01:00
|
|
|
* processors where sizeof(pointer) < sizeof(uint32_t).
|
2007-02-21 22:55:16 +01:00
|
|
|
* see wdog.h.
|
|
|
|
*/
|
|
|
|
|
2015-05-18 16:53:42 +02:00
|
|
|
union wdparm_u wdparm;
|
2014-04-25 19:59:17 +02:00
|
|
|
wdparm.pvarg = (FAR void *)rtcb;
|
2007-02-21 22:55:16 +01:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* Start the watchdog */
|
|
|
|
|
2018-01-31 17:09:14 +01:00
|
|
|
(void)wd_start(rtcb->waitdog, waitticks,
|
|
|
|
(wdentry_t)nxsig_timeout, 1, wdparm.pvarg);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-11-30 13:54:15 +01:00
|
|
|
/* Now wait for either the signal or the watchdog, but
|
|
|
|
* first, make sure this is not the idle task,
|
|
|
|
* descheduling that isn't going to end well.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-11-30 13:54:15 +01:00
|
|
|
DEBUGASSERT(NULL != rtcb->flink);
|
2007-02-18 00:21:28 +01:00
|
|
|
up_block_task(rtcb, TSTATE_WAIT_SIG);
|
|
|
|
|
|
|
|
/* We no longer need the watchdog */
|
|
|
|
|
2013-02-06 16:43:28 +01:00
|
|
|
wd_delete(rtcb->waitdog);
|
|
|
|
rtcb->waitdog = NULL;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
2014-01-23 00:14:10 +01:00
|
|
|
|
|
|
|
/* REVISIT: And do what if there are no watchdog timers? The wait
|
|
|
|
* will fail and we will return something bogus.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* No timeout, just wait */
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2018-11-30 13:54:15 +01:00
|
|
|
/* And wait until one of the unblocked signals is posted,
|
|
|
|
* but first make sure this is not the idle task,
|
|
|
|
* descheduling that isn't going to end well.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-11-30 13:54:15 +01:00
|
|
|
DEBUGASSERT(NULL != rtcb->flink);
|
2007-02-18 00:21:28 +01:00
|
|
|
up_block_task(rtcb, TSTATE_WAIT_SIG);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We are running again, clear the sigwaitmask */
|
|
|
|
|
|
|
|
rtcb->sigwaitmask = NULL_SIGNAL_SET;
|
|
|
|
|
2012-05-30 17:36:46 +02:00
|
|
|
/* When we awaken, the cause will be in the TCB. Get the signal number
|
|
|
|
* or timeout) that awakened us.
|
2007-02-18 00:21:28 +01:00
|
|
|
*/
|
|
|
|
|
2012-05-30 17:36:46 +02:00
|
|
|
if (GOOD_SIGNO(rtcb->sigunbinfo.si_signo))
|
2007-02-18 00:21:28 +01:00
|
|
|
{
|
2012-05-30 17:36:46 +02:00
|
|
|
/* We were awakened by a signal... but is it one of the signals that
|
|
|
|
* we were waiting for?
|
|
|
|
*/
|
2014-03-21 18:22:50 +01:00
|
|
|
|
2012-05-30 17:36:46 +02:00
|
|
|
if (sigismember(set, rtcb->sigunbinfo.si_signo))
|
|
|
|
{
|
|
|
|
/* Yes.. the return value is the number of the signal that
|
|
|
|
* awakened us.
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2012-05-30 17:36:46 +02:00
|
|
|
ret = rtcb->sigunbinfo.si_signo;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-06 16:28:20 +02:00
|
|
|
/* No... then report the EINTR error */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-10-06 16:28:20 +02:00
|
|
|
ret = -EINTR;
|
2012-05-30 17:36:46 +02:00
|
|
|
}
|
2011-11-29 19:21:52 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-12 16:55:19 +02:00
|
|
|
/* Otherwise, we must have been awakened by the timeout or,
|
|
|
|
* perhaps, the wait was cancelled.
|
2012-05-30 17:36:46 +02:00
|
|
|
*/
|
2011-11-29 19:21:52 +01:00
|
|
|
|
2017-10-12 16:55:19 +02:00
|
|
|
#ifdef CONFIG_CANCELLATION_POINTS
|
|
|
|
if (rtcb->sigunbinfo.si_signo == SIG_CANCEL_TIMEOUT)
|
|
|
|
{
|
|
|
|
/* The wait was canceled */
|
|
|
|
|
|
|
|
ret = -rtcb->sigunbinfo.si_errno;
|
|
|
|
DEBUGASSERT(ret < 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* We were awakened by a timeout. Set EAGAIN and return an
|
|
|
|
* error.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT(rtcb->sigunbinfo.si_signo == SIG_WAIT_TIMEOUT);
|
|
|
|
ret = -EAGAIN;
|
|
|
|
}
|
2012-05-30 17:36:46 +02:00
|
|
|
}
|
2014-03-21 18:22:50 +01:00
|
|
|
|
2012-05-30 17:36:46 +02:00
|
|
|
/* Return the signal info to the caller if so requested */
|
|
|
|
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
memcpy(info, &rtcb->sigunbinfo, sizeof(struct siginfo));
|
2011-11-29 19:21:52 +01:00
|
|
|
}
|
2012-12-24 15:31:02 +01:00
|
|
|
|
2016-02-14 15:17:46 +01:00
|
|
|
leave_critical_section(flags);
|
2015-10-08 03:59:14 +02:00
|
|
|
}
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2017-10-06 16:28:20 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: sigtimedwait
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function selects the pending signal set specified by the argument
|
|
|
|
* set. If multiple signals are pending in set, it will remove and return
|
|
|
|
* the lowest numbered one. If no signals in set are pending at the time
|
|
|
|
* of the call, the calling process will be suspended until one of the
|
|
|
|
* signals in set becomes pending, OR until the process is interrupted by
|
|
|
|
* an unblocked signal, OR until the time interval specified by timeout
|
|
|
|
* (if any), has expired. If timeout is NULL, then the timeout interval
|
|
|
|
* is forever.
|
|
|
|
*
|
|
|
|
* If the info argument is non-NULL, the selected signal number is stored
|
|
|
|
* in the si_signo member and the cause of the signal is store din the
|
|
|
|
* si_code member. The content of si_value is only meaningful if the
|
|
|
|
* signal was generated by sigqueue().
|
|
|
|
*
|
|
|
|
* The following values for si_code are defined in signal.h:
|
|
|
|
* SI_USER - Signal sent from kill, raise, or abort
|
|
|
|
* SI_QUEUE - Signal sent from sigqueue
|
|
|
|
* SI_TIMER - Signal is result of timer expiration
|
|
|
|
* SI_ASYNCIO - Signal is the result of asynch IO completion
|
|
|
|
* SI_MESGQ - Signal generated by arrival of a message on an
|
|
|
|
* empty message queue.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-10-06 16:28:20 +02:00
|
|
|
* set - The pending signal set.
|
|
|
|
* info - The returned value (may be NULL).
|
|
|
|
* timeout - The amount of time to wait (may be NULL)
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-10-06 16:28:20 +02:00
|
|
|
* Signal number that cause the wait to be terminated, otherwise -1 (ERROR)
|
|
|
|
* is returned with errno set to either:
|
|
|
|
*
|
|
|
|
* EAGAIN - No signal specified by set was generated within the specified
|
|
|
|
* timeout period.
|
|
|
|
* EINTR - The wait was interrupted by an unblocked, caught signal.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *info,
|
|
|
|
FAR const struct timespec *timeout)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* sigtimedwait() is a cancellation point */
|
|
|
|
|
|
|
|
(void)enter_cancellation_point();
|
|
|
|
|
|
|
|
/* Let nxsig_timedwait() do the work. */
|
|
|
|
|
|
|
|
ret = nxsig_timedwait(set, info, timeout);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
set_errno(-ret);
|
|
|
|
ret = ERROR;
|
|
|
|
}
|
|
|
|
|
2016-12-09 23:50:34 +01:00
|
|
|
leave_cancellation_point();
|
2015-10-08 03:59:14 +02:00
|
|
|
return ret;
|
2007-02-18 00:21:28 +01:00
|
|
|
}
|