From 66b0f6eb3523625c9b604ec2bf826bc0a15869d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Fri, 17 Feb 2023 12:01:15 +0100 Subject: [PATCH] log_writer_file: call fsync after reliable transfer ensures watchdog data is flushed immediately --- src/modules/logger/log_writer_file.cpp | 3 ++- src/modules/logger/log_writer_file.h | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/modules/logger/log_writer_file.cpp b/src/modules/logger/log_writer_file.cpp index 1ef9af4462..873da36d3e 100644 --- a/src/modules/logger/log_writer_file.cpp +++ b/src/modules/logger/log_writer_file.cpp @@ -369,7 +369,8 @@ void LogWriterFile::run() const hrt_abstime now = hrt_absolute_time(); /* call fsync periodically to minimize potential loss of data */ - const bool call_fsync = ++poll_count >= 100 || now - last_fsync > 1_s; + const bool call_fsync = ++poll_count >= 100 || now - last_fsync > 1_s || _want_fsync.load(); + _want_fsync.store(false); if (call_fsync) { last_fsync = now; diff --git a/src/modules/logger/log_writer_file.h b/src/modules/logger/log_writer_file.h index f103a4eb50..218f127258 100644 --- a/src/modules/logger/log_writer_file.h +++ b/src/modules/logger/log_writer_file.h @@ -120,6 +120,10 @@ public: void set_need_reliable_transfer(bool need_reliable) { + if (!need_reliable && _need_reliable_transfer) { + _want_fsync.store(true); + } + _need_reliable_transfer = need_reliable; } @@ -210,6 +214,7 @@ private: px4::atomic_bool _exit_thread{false}; bool _need_reliable_transfer{false}; + px4::atomic_bool _want_fsync{false}; pthread_mutex_t _mtx; pthread_cond_t _cv; pthread_t _thread = 0;