fix(shutdown): move shutdown_time_us_now() inside workqueue guard

shutdown_time_us_now() was defined unconditionally at file scope but its
only callers (shutdown_worker, px4_reboot_request, px4_shutdown_request)
all live inside

  #if defined(CONFIG_SCHED_WORKQUEUE) || \
      (!defined(CONFIG_BUILD_FLAT) && defined(CONFIG_LIBC_USRWORK))

On NuttX bootloader builds and on flat-build defconfigs without
CONFIG_LIBC_USRWORK the function was therefore dead code, and the
NuttX build flags include -Werror=unused-function which made it a
fatal error across stm32f4 / stm32h7 / imxrt / s32k / kinetis board
targets.

Move the helper inside the same guard as its callers so it only exists
where it is used. No behavioural change for builds that already linked
against it.

Signed-off-by: Nuno Marques <n.marques21@hotmail.com>
This commit is contained in:
Nuno Marques
2026-05-07 16:15:31 -07:00
parent abd1adf443
commit b463416559
+14 -14
View File
@@ -65,20 +65,6 @@
using namespace time_literals;
#if defined(ENABLE_LOCKSTEP_SCHEDULER) && defined(__PX4_WINDOWS)
static hrt_abstime shutdown_time_us_now()
{
timespec ts{};
system_clock_gettime(CLOCK_MONOTONIC, &ts);
return (static_cast<hrt_abstime>(ts.tv_sec) * 1000000ULL) + (static_cast<hrt_abstime>(ts.tv_nsec) / 1000ULL);
}
#else
static hrt_abstime shutdown_time_us_now()
{
return hrt_absolute_time();
}
#endif
static pthread_mutex_t shutdown_mutex =
PTHREAD_MUTEX_INITIALIZER; // protects access to shutdown_hooks & shutdown_lock_counter
static uint8_t shutdown_lock_counter = 0;
@@ -120,6 +106,20 @@ int px4_shutdown_unlock()
#if defined(CONFIG_SCHED_WORKQUEUE) || (!defined(CONFIG_BUILD_FLAT) && defined(CONFIG_LIBC_USRWORK))
#if defined(ENABLE_LOCKSTEP_SCHEDULER) && defined(__PX4_WINDOWS)
static hrt_abstime shutdown_time_us_now()
{
timespec ts{};
system_clock_gettime(CLOCK_MONOTONIC, &ts);
return (static_cast<hrt_abstime>(ts.tv_sec) * 1000000ULL) + (static_cast<hrt_abstime>(ts.tv_nsec) / 1000ULL);
}
#else
static hrt_abstime shutdown_time_us_now()
{
return hrt_absolute_time();
}
#endif
static struct work_s shutdown_work = {};
static uint16_t shutdown_counter = 0; ///< count how many times the shutdown worker was executed