diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h index 25bba86ba17e2939c84fd7961b0b3313878f8ff7..6e525f6e1c707ed79f01af7b324fb1e9bf1d1915 100644 --- a/include/nuttx/semaphore.h +++ b/include/nuttx/semaphore.h @@ -68,9 +68,9 @@ * (libuc.a and libunx.a). The that case, the correct interface must be * used for the build context. * - * The interfaces sem_twait() and sem_timedwait() are cancellation points. + * The interfaces sem_wait() and sem_timedwait() are cancellation points. * - * REVISIT: The fact that sem_twait() and sem_timedwait() are cancellation + * REVISIT: The fact that sem_wait() and sem_timedwait() are cancellation * points is an issue and may cause violations: It use of these internally * will cause the calling function to become a cancellation points! */ diff --git a/include/nuttx/signal.h b/include/nuttx/signal.h index cf3bc0d48dcd041f6c23b6cc9833f0161e576828..0c9e4107129fd86adb8d16f672521fc5c4e1b94c 100644 --- a/include/nuttx/signal.h +++ b/include/nuttx/signal.h @@ -45,6 +45,51 @@ #include <sys/types.h> #include <signal.h> +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* Most internal nxsig_* interfaces are not available in the user space in + * PROTECTED and KERNEL builds. In that context, the application signal + * interfaces must be used. The differences between the two sets of + * interfaces are: (1) the nxsig_* interfaces do not cause cancellation + * points and (2) they do not modify the errno variable. + * + * This is only important when compiling libraries (libc or libnx) that are + * used both by the OS (libkc.a and libknx.a) or by the applications + * (libuc.a and libunx.a). The that case, the correct interface must be + * used for the build context. + * + * The interfaces sigtimedwait(), sigwait(), sigwaitinfo(), sleep(), + * nanosleep(), and usleep() are cancellation points. + * + * REVISIT: The fact that these interfaces are cancellation points is an + * issue and may cause violations: It use of these internally will cause + * the calling function to become a cancellation points! + */ + +#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) +# define _SIG_PROCMASK(h,s,o) nxsig_procmask(h,s,o) +# define _SIG_QUEUE(p,s,v) nxsig_queue(p,s,v) +# define _SIG_KILL(p,s) nxsig_kill(p,s); +# define _SIG_WAITINFO(s,i) nxsig_timedwait(s,i,NULL) +# define _SIG_NANOSLEEP(r,a) nxsig_nanosleep(r,a) +# define _SIG_SLEEP(s) nxsig_sleep(s) +# define _SIG_USLEEP(u) nxsig_usleep(u) +# define _SIG_ERRNO(r) (-(r)) +# define _SIG_ERRVAL(r) (r) +#else +# define _SIG_PROCMASK(h,s,o) sigprocmask(h,s,o) +# define _SIG_QUEUE(p,s,v) sigqueue(p,s,v) +# define _SIG_KILL(p,s) kill(p,s); +# define _SIG_WAITINFO(s,i) sigwaitinfo(s,i) +# define _SIG_NANOSLEEP(r,a) nanosleep(r,a) +# define _SIG_SLEEP(s) sleep(s) +# define _SIG_USLEEP(u) usleep(u) +# define _SIG_ERRNO(r) errno +# define _SIG_ERRVAL(r) (-errno) +#endif + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -129,7 +174,7 @@ int nxsig_procmask(int how, FAR const sigset_t *set, FAR sigset_t *oset); ****************************************************************************/ #ifdef CONFIG_CAN_PASS_STRUCTS -int nxsig_queue (int pid, int signo, union sigval value); +int nxsig_queue(int pid, int signo, union sigval value); #else int nxsig_queue(int pid, int signo, void *sival_ptr); #endif @@ -236,6 +281,8 @@ int nxsig_kill(pid_t pid, int signo); * ****************************************************************************/ +int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info, + FAR const struct timespec *timeout); int nxsig_timedwait(FAR const sigset_t *set, FAR struct siginfo *info, FAR const struct timespec *timeout); diff --git a/libnx/nxmu/nx_connect.c b/libnx/nxmu/nx_connect.c index 662a102bd39fb8726ecf7e53a5490d199e2c4685..00b93934e3c2232f2b58a17761f1e52d4c8635c8 100644 --- a/libnx/nxmu/nx_connect.c +++ b/libnx/nxmu/nx_connect.c @@ -48,6 +48,7 @@ #include <errno.h> #include <debug.h> +#include <nuttx/signal.h> #include <nuttx/semaphore.h> #include <nuttx/nx/nx.h> #include <nuttx/nx/nxmu.h> @@ -190,7 +191,8 @@ NXHANDLE nx_connectinstance(FAR const char *svrmqname) gerr("ERROR: nx_message failed: %d\n", errno); goto errout_with_wmq; } - usleep(300000); + + _SIG_USLEEP(300000); } while (conn->state != NX_CLISTATE_CONNECTED); #endif