From 9e66938f68750bd039313baf966ec0682b17e28a Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Wed, 2 Aug 2017 01:39:30 -0700 Subject: [PATCH] AP_HAL_PX4: Scheduler: replace use of in_timerprocess() This function actually checks if we are not in the main thread rather than if we are in the timer thread. Add a new function that does what it's supposed to do. --- libraries/AP_HAL_PX4/Scheduler.cpp | 7 ++++++- libraries/AP_HAL_PX4/Scheduler.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/AP_HAL_PX4/Scheduler.cpp b/libraries/AP_HAL_PX4/Scheduler.cpp index 83c1188ede..1ad473f7ab 100644 --- a/libraries/AP_HAL_PX4/Scheduler.cpp +++ b/libraries/AP_HAL_PX4/Scheduler.cpp @@ -173,7 +173,7 @@ void PX4Scheduler::delay_microseconds_boost(uint16_t usec) void PX4Scheduler::delay(uint16_t ms) { - if (in_timerprocess()) { + if (!in_main_thread()) { ::printf("ERROR: delay() from timer process\n"); return; } @@ -448,6 +448,11 @@ bool PX4Scheduler::in_timerprocess() return getpid() != _main_task_pid; } +bool PX4Scheduler::in_main_thread() +{ + return getpid() == _main_task_pid; +} + void PX4Scheduler::system_initialized() { if (_initialized) { diff --git a/libraries/AP_HAL_PX4/Scheduler.h b/libraries/AP_HAL_PX4/Scheduler.h index 6d302bb669..e09715740b 100644 --- a/libraries/AP_HAL_PX4/Scheduler.h +++ b/libraries/AP_HAL_PX4/Scheduler.h @@ -59,6 +59,7 @@ public: void reboot(bool hold_in_bootloader); bool in_timerprocess(); + bool in_main_thread(); void system_initialized(); void hal_initialized() { _hal_initialized = true; }