Fix wait loop and void cast (#24)

* Simplify EINTR/ECANCEL error handling

1. Add semaphore uninterruptible wait function
2 .Replace semaphore wait loop with a single uninterruptible wait
3. Replace all sem_xxx to nxsem_xxx

* Unify the void cast usage

1. Remove void cast for function because many place ignore the returned value witout cast
2. Replace void cast for variable with UNUSED macro
This commit is contained in:
Xiang Xiao
2020-01-02 10:49:34 -06:00
committed by Gregory Nutt
parent 316675f4db
commit 6a3c2aded6
1602 changed files with 6311 additions and 10874 deletions
+38
View File
@@ -403,6 +403,44 @@ int net_timedwait(sem_t *sem, FAR const struct timespec *abstime);
int net_lockedwait(sem_t *sem);
/****************************************************************************
* Name: net_timedwait_uninterruptible
*
* Description:
* This function is wrapped version of net_timedwait(), which is
* uninterruptible and convenient for use.
*
* Input Parameters:
* sem - A reference to the semaphore to be taken.
* abstime - The absolute time to wait until a timeout is declared.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure.
*
****************************************************************************/
int net_timedwait_uninterruptible(sem_t *sem,
FAR const struct timespec *abstime);
/****************************************************************************
* Name: net_lockedwait_uninterruptible
*
* Description:
* This function is wrapped version of net_lockedwait(), which is
* uninterruptible and convenient for use.
*
* Input Parameters:
* sem - A reference to the semaphore to be taken.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure.
*
****************************************************************************/
int net_lockedwait_uninterruptible(sem_t *sem);
/****************************************************************************
* Name: net_ioballoc
*
+79 -1
View File
@@ -191,7 +191,7 @@ int nxsem_init(FAR sem_t *sem, int pshared, unsigned int value);
*
****************************************************************************/
int nxsem_destroy (FAR sem_t *sem);
int nxsem_destroy(FAR sem_t *sem);
/****************************************************************************
* Name: nxsem_wait
@@ -554,6 +554,84 @@ static inline int nxsem_wait_uninterruptible(FAR sem_t *sem)
return ret;
}
/****************************************************************************
* Name: nxsem_timedwait_uninterruptible
*
* Description:
* This function is wrapped version of nxsem_timedwait(), which is
* uninterruptible and convenient for use.
*
* Input Parameters:
* sem - Semaphore object
* abstime - The absolute time to wait until a timeout is declared.
*
* Returned Value:
* EINVAL The sem argument does not refer to a valid semaphore. Or the
* thread would have blocked, and the abstime parameter specified
* a nanoseconds field value less than zero or greater than or
* equal to 1000 million.
* ETIMEDOUT The semaphore could not be locked before the specified timeout
* expired.
* EDEADLK A deadlock condition was detected.
*
****************************************************************************/
static inline int
nxsem_timedwait_uninterruptible(FAR sem_t *sem,
FAR const struct timespec *abstime)
{
int ret;
do
{
/* Take the semaphore (perhaps waiting) */
ret = nxsem_timedwait(sem, abstime);
}
while (ret == -EINTR || ret == -ECANCELED);
return ret;
}
/****************************************************************************
* Name: nxsem_tickwait_uninterruptible
*
* Description:
* This function is wrapped version of nxsem_tickwait(), which is
* uninterruptible and convenient for use.
*
* Input Parameters:
* sem - Semaphore object
* start - The system time that the delay is relative to. If the
* current time is not the same as the start time, then the
* delay will be adjust so that the end time will be the same
* in any event.
* delay - Ticks to wait from the start time until the semaphore is
* posted. If ticks is zero, then this function is equivalent
* to sem_trywait().
*
* Returned Value:
* Zero (OK) is returned on success. A negated errno value is returned
* on failure. -ETIMEDOUT is returned on the timeout condition.
*
****************************************************************************/
static inline int
nxsem_tickwait_uninterruptible(FAR sem_t *sem, clock_t start, uint32_t delay)
{
int ret;
do
{
/* Take the semaphore (perhaps waiting) */
ret = nxsem_tickwait(sem, start, delay);
}
while (ret == -EINTR || ret == -ECANCELED);
return ret;
}
#undef EXTERN
#ifdef __cplusplus
}
+2 -2
View File
@@ -90,12 +90,12 @@ static inline int bcmp(FAR const void *b1, FAR const void *b2, size_t len)
static inline void bcopy(FAR const void *b1, FAR void *b2, size_t len)
{
(void)memmove(b2, b1, len);
memmove(b2, b1, len);
}
static inline void bzero(FAR void *s, size_t len)
{
(void)memset(s, 0, len);
memset(s, 0, len);
}
static inline FAR char *index(FAR const char *s, int c)