From 0c9a4ac4f91013fdde36fa39cfe85f6256e3da1c Mon Sep 17 00:00:00 2001 From: liuhaiyang Date: Mon, 27 Aug 2018 06:07:50 -0600 Subject: [PATCH] nclude/nuttx/semaphore: apply the semaphore wait function nxsem_wait_uninterruptible(). The function nxsem_wait_uninterruptible() is a wrapped version of nxsem_wait(), which is uninterruptible and convenient for use. --- include/nuttx/semaphore.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h index c736086f117..4a44f2f4ea6 100644 --- a/include/nuttx/semaphore.h +++ b/include/nuttx/semaphore.h @@ -42,6 +42,7 @@ #include +#include #include #include @@ -523,6 +524,37 @@ int nxsem_setprotocol(FAR sem_t *sem, int protocol); int sem_setprotocol(FAR sem_t *sem, int protocol); +/**************************************************************************** + * Name: nxsem_wait_uninterruptible + * + * Description: + * This function is wrapped version of nxsem_wait(), which is uninterruptible + * and convenient for use. + * + * Parameters: + * sem - Semaphore descriptor. + * + * Return Value: + * Zero(OK) - On success + * EINVAL - Invalid attempt to get the semaphore + * + ****************************************************************************/ + +static inline int nxsem_wait_uninterruptible(FAR sem_t *sem) +{ + int ret; + + do + { + /* Take the semaphore (perhaps waiting) */ + + ret = nxsem_wait(sem); + } + while (ret == -EINTR || ret == -ECANCELED); + + return ret; +} + #undef EXTERN #ifdef __cplusplus }