platforms: prevent wrap-arounds in px4_sleep

@bkueng found that the old implementation was likely to wrap-around
given seconds is only a uint32_t. We now cast it directly to uint64_t
and therefore should fix this problem.
This commit is contained in:
Julian Oes 2018-11-27 11:09:19 +01:00
parent 4efe4b0d15
commit 5280a4aba1

View File

@ -641,8 +641,16 @@ int px4_usleep(useconds_t usec)
unsigned int px4_sleep(unsigned int seconds)
{
useconds_t usec = seconds * 1000000;
return px4_usleep(usec);
if (px4_timestart_monotonic == 0) {
// Until the time is set by the simulator, we fallback to the normal
// sleep;
return system_sleep(seconds);
}
const uint64_t time_finished = lockstep_scheduler.get_absolute_time() +
((uint64_t)seconds * 1000000);
return lockstep_scheduler.usleep_until(time_finished);
}
int px4_pthread_cond_timedwait(pthread_cond_t *cond,