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.

This commit is contained in:
liuhaiyang 2018-08-27 06:07:50 -06:00 committed by Gregory Nutt
parent 8980b08fae
commit 0c9a4ac4f9

View File

@ -42,6 +42,7 @@
#include <nuttx/config.h>
#include <errno.h>
#include <semaphore.h>
#include <nuttx/clock.h>
@ -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
}