Skip to content
Snippets Groups Projects
Commit 032e64aa authored by Julian Oes's avatar Julian Oes Committed by Lorenz Meier
Browse files

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.
parent 23653f9f
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment