This commit adds internal versions of the signal interfaces:

sigtimedwait() -> nxsig_timedwait()
  sigwaitinfo()  -> nxsig_waitinfo()
  nanosleep()    -> nxsig_nanosleep()

The internal OS versions differ from the standard application interfaces in that:

  - They do not create cancellation points, and
  - they do not modify the application's errno variable

Squashed commit of the following:

    sched/signal:  Replace all usage of sigwaitinfo(), sigtimedwait(), and nanosleep() with the OS internal counterparts nxsig_waitinfo(), nxsig_timedwait(), and nxsig_nanosleep().

    sched/signal:  Add nxsig_nanosleep().  This is an internal OS version of nanosleep().  It differs in that it does not set the errno varaiable and does not create a cancellation point.

    sched/signal:  Add nxsig_timedwait() and nxsig_waitinfo().  These are internal OS versions of sigtimedwait() and sigwaitinfo().  They differ in that they do not set the errno varaiable and they do not create cancellation points.
This commit is contained in:
Gregory Nutt
2017-10-06 08:28:20 -06:00
parent aeb3944f0a
commit fdd0dcc0b6
8 changed files with 390 additions and 144 deletions
+124 -3
View File
@@ -45,12 +45,132 @@
#include <sys/types.h>
#include <signal.h>
#if defined(CONFIG_SIG_EVTHREAD) && defined(CONFIG_BUILD_FLAT)
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
struct timespec; /* Forward reference */
/****************************************************************************
* Name: nxsig_waitinfo
*
* Description:
* This function is equivalent to nxsig_timedwait with a NULL timeout
* parameter.
*
* This is an internal OS interface. It is functionally equivalent to
* sigwaitinfo() except that:
*
* - It is not a cancellaction point, and
* - It does not modify the errno value.
*
* Parameters:
* set - The pending signal set
* info - The returned value
*
* Return Value:
* 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.
*
****************************************************************************/
#define nxsig_waitinfo(s,i) nxsig_timedwait(s,i,NULL)
/****************************************************************************
* Name: nxsig_timedwait
*
* 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().
*
* 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.
*
* Parameters:
* set - The pending signal set.
* info - The returned value (may be NULL).
* timeout - The amount of time to wait (may be NULL)
*
* Return Value:
* 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.
*
* EAGAIN - No signal specified by set was generated within the specified
* timeout period.
* EINTR - The wait was interrupted by an unblocked, caught signal.
*
****************************************************************************/
int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info,
FAR const struct timespec *timeout);
/****************************************************************************
* Name: nxsig_nanosleep
*
* Description:
* The nxsig_nanosleep() function causes the current thread to be
* suspended from execution until either the time interval specified by
* the rqtp argument has elapsed or a signal is delivered to the calling
* thread and its action is to invoke a signal-catching function or to
* terminate the process. The suspension time may be longer than requested
* because the argument value is rounded up to an integer multiple of the
* sleep resolution or because of the scheduling of other activity by the
* system. But, except for the case of being interrupted by a signal, the
* suspension time will not be less than the time specified by rqtp, as
* measured by the system clock, CLOCK_REALTIME.
*
* The use of the nxsig_nanosleep() function has no effect on the action
* or blockage of any signal.
*
* Parameters:
* rqtp - The amount of time to be suspended from execution.
* rmtp - If the rmtp argument is non-NULL, the timespec structure
* referenced by it is updated to contain the amount of time
* remaining in the interval (the requested time minus the time
* actually slept)
*
* Returned Value:
* If the nxsig_nanosleep() function returns because the requested time
* has elapsed, its return value is zero.
*
* If the nxsig_nanosleep() function returns because it has been
* interrupted by a signal, the function returns a negated errno value
* indicate the interruption. If the rmtp argument is non-NULL, the
* timespec structure referenced by it is updated to contain the amount
* of time remaining in the interval (the requested time minus the time
* actually slept). If the rmtp argument is NULL, the remaining time is
* not returned.
*
* If nxsig_nanosleep() fails, it returns a negated errno indicating the
* cause of the failure. The nxsig_nanosleep() function will fail if:
*
* EINTR - The nxsig_nanosleep() function was interrupted by a signal.
* EINVAL - The rqtp argument specified a nanosecond value less than
* zero or greater than or equal to 1000 million.
* ENOSYS - The nxsig_nanosleep() function is not supported by this
* implementation.
*
****************************************************************************/
int nxsig_nanosleep(FAR const struct timespec *rqtp,
FAR struct timespec *rmtp);
/****************************************************************************
* Name: nxsig_notification
*
@@ -71,7 +191,8 @@
*
****************************************************************************/
#if defined(CONFIG_SIG_EVTHREAD) && defined(CONFIG_BUILD_FLAT)
int nxsig_notification(pid_t pid, FAR struct sigevent *event);
#endif
#endif /* CONFIG_SIG_EVTHREAD && CONFIG_BUILD_FLAT */
#endif /* __INCLUDE_NUTTX_SIGNAL_H */