diff --git a/src/drivers/device/vdev_posix.cpp b/src/drivers/device/vdev_posix.cpp index 3e140e907c6..b07b6c1f4b0 100644 --- a/src/drivers/device/vdev_posix.cpp +++ b/src/drivers/device/vdev_posix.cpp @@ -301,6 +301,9 @@ extern "C" { // Execute a blocking wait for that time in the future errno = 0; ret = px4_sem_timedwait(&sem, &ts); +#ifndef __PX4_DARWIN + ret = errno; +#endif // Ensure ret is negative on failure if (ret > 0) { diff --git a/src/platforms/posix/px4_layer/px4_sem.cpp b/src/platforms/posix/px4_layer/px4_sem.cpp index 777741ef06d..67e59bc8fd9 100644 --- a/src/platforms/posix/px4_layer/px4_sem.cpp +++ b/src/platforms/posix/px4_layer/px4_sem.cpp @@ -95,6 +95,7 @@ int px4_sem_timedwait(px4_sem_t *s, const struct timespec *abstime) } s->value--; + errno = 0; if (s->value < 0) { ret = pthread_cond_timedwait(&(s->wait), &(s->lock), abstime); @@ -103,10 +104,7 @@ int px4_sem_timedwait(px4_sem_t *s, const struct timespec *abstime) ret = 0; } - int err = errno; -#ifdef __PX4_DARWIN - err = ret; -#endif + int err = ret; if (err != 0 && err != ETIMEDOUT) { setbuf(stdout, NULL); @@ -119,7 +117,7 @@ int px4_sem_timedwait(px4_sem_t *s, const struct timespec *abstime) int mret = pthread_mutex_unlock(&(s->lock)); - return (ret) ? ret : mret; + return (err) ? err : mret; } int px4_sem_post(px4_sem_t *s)