diff --git a/include/nuttx/semaphore.h b/include/nuttx/semaphore.h index c736086f11..4a44f2f4ea 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 }