px4_sem: set errno, return -1 on any error

- Don't duplicate the ret variable to err.
- Return -1 on any error, 0 otherwise.
- Set errno to return value of pthread_cond_timedwait.
This commit is contained in:
Julian Oes
2019-01-01 20:01:57 +01:00
committed by Lorenz Meier
parent 23653f9f39
commit 032e64aaf2

View File

@@ -140,20 +140,24 @@ int px4_sem_timedwait(px4_sem_t *s, const struct timespec *abstime)
ret = 0;
}
int err = ret;
errno = ret;
if (err != 0 && err != ETIMEDOUT) {
if (ret != 0 && ret != ETIMEDOUT) {
setbuf(stdout, nullptr);
setbuf(stderr, nullptr);
const unsigned NAMELEN = 32;
char thread_name[NAMELEN] = {};
(void)pthread_getname_np(pthread_self(), thread_name, NAMELEN);
PX4_WARN("%s: px4_sem_timedwait failure: ret: %d, %s", thread_name, ret, strerror(err));
PX4_WARN("%s: px4_sem_timedwait failure: ret: %d, %s", thread_name, ret, strerror(ret));
}
int mret = pthread_mutex_unlock(&(s->lock));
return (err) ? err : mret;
if (ret || mret) {
return -1;
}
return 0;
}
int px4_sem_post(px4_sem_t *s)