From ebd64bfab60231dcc8350da9630be006469a9086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Thu, 15 Jun 2023 15:10:06 +0200 Subject: [PATCH] navigator: defer saving mission until disarmed Avoids unnecessary dataman accesses --- src/modules/navigator/mission.cpp | 11 +++++++++++ src/modules/navigator/mission.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/modules/navigator/mission.cpp b/src/modules/navigator/mission.cpp index dd2d85ed88..5465c65053 100644 --- a/src/modules/navigator/mission.cpp +++ b/src/modules/navigator/mission.cpp @@ -122,6 +122,10 @@ Mission::on_inactive() return; } + if (_need_mission_save && _navigator->get_vstatus()->arming_state != vehicle_status_s::ARMING_STATE_ARMED) { + save_mission_state(); + } + if (_inited) { if (_mission_sub.updated()) { update_mission(); @@ -1752,6 +1756,13 @@ Mission::read_mission_item(int offset, struct mission_item_s *mission_item) void Mission::save_mission_state() { + if (_navigator->get_vstatus()->arming_state == vehicle_status_s::ARMING_STATE_ARMED) { + // Save only while disarmed, as this is a blocking operation + _need_mission_save = true; + return; + } + + _need_mission_save = false; mission_s mission_state = {}; /* read current state */ diff --git a/src/modules/navigator/mission.h b/src/modules/navigator/mission.h index be53a52ca3..be6b217cb5 100644 --- a/src/modules/navigator/mission.h +++ b/src/modules/navigator/mission.h @@ -348,6 +348,7 @@ private: bool _inited{false}; bool _home_inited{false}; bool _need_mission_reset{false}; + bool _need_mission_save{false}; bool _mission_waypoints_changed{false}; bool _mission_changed{false}; /** < true if the mission changed since the mission mode was active */