mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-30 16:23:34 +08:00
POSIX: get px4_poll right
Like this the timeouts are going through instead of hanging everything.
This commit is contained in:
@@ -314,7 +314,7 @@ extern "C" {
|
|||||||
|
|
||||||
// Get the current time
|
// Get the current time
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
px4_clock_gettime(CLOCK_REALTIME, &ts);
|
px4_clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
|
||||||
// Calculate an absolute time in the future
|
// Calculate an absolute time in the future
|
||||||
const unsigned billion = (1000 * 1000 * 1000);
|
const unsigned billion = (1000 * 1000 * 1000);
|
||||||
|
|||||||
@@ -371,8 +371,12 @@ int px4_sem_timedwait(px4_sem_t *sem, const struct timespec *ts)
|
|||||||
{
|
{
|
||||||
work_s _hpwork = {};
|
work_s _hpwork = {};
|
||||||
|
|
||||||
|
// Get the current time.
|
||||||
|
struct timespec ts_now;
|
||||||
|
px4_clock_gettime(CLOCK_MONOTONIC, &ts_now);
|
||||||
|
|
||||||
// We get an absolute time but want to calculate a timeout in us.
|
// We get an absolute time but want to calculate a timeout in us.
|
||||||
hrt_abstime timeout_us = ts_to_abstime((struct timespec *)ts) - hrt_absolute_time();
|
hrt_abstime timeout_us = ts_to_abstime((struct timespec *)ts) - ts_to_abstime(&ts_now);
|
||||||
|
|
||||||
// Create a timer to unblock.
|
// Create a timer to unblock.
|
||||||
hrt_work_queue(&_hpwork, (worker_t)&timer_cb, (void *)sem, timeout_us);
|
hrt_work_queue(&_hpwork, (worker_t)&timer_cb, (void *)sem, timeout_us);
|
||||||
|
|||||||
Reference in New Issue
Block a user