From b8a94bf8d44486f8d431fbcb7ebc627afe03dcaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Thu, 3 May 2018 13:18:45 +0200 Subject: [PATCH] logger: move pthread_t cast to pid_t into watchdog_initialize avoids compile error on OSX, trying to cast pthread_t to pid_t --- src/modules/logger/logger.cpp | 5 ++--- src/modules/logger/watchdog.cpp | 5 ++++- src/modules/logger/watchdog.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/modules/logger/logger.cpp b/src/modules/logger/logger.cpp index cdf775a9af..04331ced0e 100644 --- a/src/modules/logger/logger.cpp +++ b/src/modules/logger/logger.cpp @@ -960,12 +960,11 @@ void Logger::run() if (_writer.backend() & LogWriter::BackendFile) { const pid_t pid_self = getpid(); - // The pthread_t ID is equal to the PID on NuttX - const pid_t pid_writer = _writer.thread_id_file(); + const pthread_t writer_thread = _writer.thread_id_file(); // sched_note_start is already called from pthread_create and task_create, // which means we can expect to find the tasks in system_load.tasks, as required in watchdog_initialize - watchdog_initialize(pid_self, pid_writer, timer_callback_data.watchdog_data); + watchdog_initialize(pid_self, writer_thread, timer_callback_data.watchdog_data); } hrt_call_every(&timer_call, _log_interval, _log_interval, timer_callback, &timer_callback_data); diff --git a/src/modules/logger/watchdog.cpp b/src/modules/logger/watchdog.cpp index 70bde053a6..146cf917dd 100644 --- a/src/modules/logger/watchdog.cpp +++ b/src/modules/logger/watchdog.cpp @@ -133,10 +133,13 @@ bool watchdog_update(watchdog_data_t &watchdog_data) } -void watchdog_initialize(const pid_t pid_logger_main, const pid_t pid_logger_writer, watchdog_data_t &watchdog_data) +void watchdog_initialize(const pid_t pid_logger_main, const pthread_t writer_thread, watchdog_data_t &watchdog_data) { #ifdef __PX4_NUTTX + // The pthread_t ID is equal to the PID on NuttX + const pthread_t pid_logger_writer = writer_thread; + sched_lock(); // need to lock the tcb access for (int i = 0; i < CONFIG_MAX_TASKS; i++) { diff --git a/src/modules/logger/watchdog.h b/src/modules/logger/watchdog.h index 96471e6d86..29def3d6bd 100644 --- a/src/modules/logger/watchdog.h +++ b/src/modules/logger/watchdog.h @@ -58,7 +58,7 @@ struct watchdog_data_t { /** * Initialize the watchdog, fill in watchdog_data. */ -void watchdog_initialize(const pid_t pid_logger_main, const pid_t pid_logger_writer, watchdog_data_t &watchdog_data); +void watchdog_initialize(const pid_t pid_logger_main, const pthread_t writer_thread, watchdog_data_t &watchdog_data); /** * Update the watchdog and trigger it if necessary. It is triggered when the log writer task is in