diff --git a/ChangeLog b/ChangeLog index d5f13d4070..c5537e17ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3651,4 +3651,6 @@ * arch/several: Change UARTs are enabled for i.MX, LM3S, ez80, and M16C to match how they are enabled for other architectures. * configs/ez80f910200kitg: Convert to use mconf configuration. + * sched/pause.c: Implements the POSIX pause() function. + diff --git a/Documentation/NuttxUserGuide.html b/Documentation/NuttxUserGuide.html index 586b744c71..5326f22805 100644 --- a/Documentation/NuttxUserGuide.html +++ b/Documentation/NuttxUserGuide.html @@ -13,7 +13,7 @@

NuttX Operating System

User's Manual

by

Gregory Nutt

-

Last Updated: August 1, 2012

+

Last Updated: November 20, 2012

@@ -3419,6 +3419,7 @@ interface of the same name.
  • 2.8.11 sigtimedwait
  • 2.8.12 sigqueue
  • 2.8.13 kill
  • +
  • 2.8.14 pause
  • 2.8.1 sigemptyset

    @@ -3946,7 +3947,7 @@ be sent. Function Prototype:
        #include <sys/types.h>
    -   #include <signal.h>
    +   #include <signal.h>
        int kill(pid_t pid, int sig);
     
    @@ -3996,6 +3997,39 @@ be sent.
  • Sending of signals to 'process groups' is not supported in NuttX.
  • +

    2.8.14 pause

    + +

    +Function Prototype: +

    +   #include <unistd.h>
    +   int pause(void);
    +
    + +

    +Description: + The pause() function will suspend the calling thread until delivery of a non-blocked signal. +

    +Input Parameters: + + +

    + Returned Value: + Since pause() suspends thread execution indefinitely unless interrupted a signal, there is no successful completion return value. + A value of -1 (ERROR will always be returned and errno set to indicate the error (EINTR). +

    + +

    + Assumptions/Limitations: +

    +

    + POSIX Compatibility: + In the POSIX description of this function is the pause() function will suspend the calling thread until delivery of a signal whose action is either to execute a signal-catching function or to terminate the process. + This implementation only waits for any non-blocked signal to be recieved. +

    +
    @@ -6711,6 +6745,7 @@ pid_t getpid(void); void _exit(int status) noreturn_function; unsigned int sleep(unsigned int seconds); void usleep(unsigned long usec); +int pause(void); int close(int fd); int dup(int fd); @@ -8187,6 +8222,7 @@ notify a task when a message is available on a queue.
  • OS Interfaces
  • +
  • pause
  • pipe
  • poll
  • poll.h
  • diff --git a/include/unistd.h b/include/unistd.h index e2ad6ff826..681ce9e632 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -133,6 +133,7 @@ EXTERN pid_t getpid(void); EXTERN void _exit(int status) noreturn_function; EXTERN unsigned int sleep(unsigned int seconds); EXTERN int usleep(useconds_t usec); +EXTERN int pause(void); /* File descriptor operations */ diff --git a/sched/Makefile b/sched/Makefile index 9b15108f4d..82f74fc3c8 100644 --- a/sched/Makefile +++ b/sched/Makefile @@ -94,7 +94,7 @@ SIGNAL_SRCS = sig_initialize.c \ sig_findaction.c sig_allocatependingsigaction.c \ sig_releasependingsigaction.c sig_unmaskpendingsignal.c \ sig_removependingsignal.c sig_releasependingsignal.c sig_lowest.c \ - sig_mqnotempty.c sig_cleanup.c sig_received.c sig_deliver.c + sig_mqnotempty.c sig_cleanup.c sig_received.c sig_deliver.c pause.c MQUEUE_SRCS = mq_open.c mq_close.c mq_unlink.c mq_send.c mq_timedsend.c\ mq_sndinternal.c mq_receive.c mq_timedreceive.c mq_rcvinternal.c \ diff --git a/sched/pause.c b/sched/pause.c new file mode 100644 index 0000000000..fb5542d84d --- /dev/null +++ b/sched/pause.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * sched/pause.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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. + * 3. Neither the name NuttX nor the names of its contributors may be + * 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. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Preprocessor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: pause + * + * Description: + * The pause() function will suspend the calling thread until delivery of a + * non-blocked signal. + * + * Input Parameters: + * None + * + * Returned Value: + * Since pause() suspends thread execution indefinitely unless interrupted + * a signal, there is no successful completion return value. A value of -1 + * will always be returned and errno set to indicate the error (EINTR). + * + * POSIX compatibility: + * In the POSIX description of this function is the pause() function will + * suspend the calling thread until delivery of a signal whose action is + * either to execute a signal-catching function or to terminate the + * process. This implementation only waits for any non-blocked signal + * to be recieved. + * + ****************************************************************************/ + +int pause(void) +{ + sigset_t set; + struct siginfo value; + + /* Set up for the sleep. Using the empty set means that we are not + * waiting for any particualar signal. However, any unmasked signal + * can still awaken sigtimedwait(). + */ + + (void)sigemptyset(&set); + + /* sigtwaitinfo() cannot succeed. It should always return error EINTR + * meaning that some unblocked signal was caught. + */ + + return sigwaitinfo(&set, &value); +}