From 0dd6415052180379c382b3de3bd96795b83915e5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 2 Dec 2019 21:16:01 +1100 Subject: [PATCH] AP_Stats: added semaphore to flttime update fixes #12948 --- libraries/AP_Stats/AP_Stats.cpp | 2 ++ libraries/AP_Stats/AP_Stats.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/AP_Stats/AP_Stats.cpp b/libraries/AP_Stats/AP_Stats.cpp index 9ccaa99a22..9c82a0e32e 100644 --- a/libraries/AP_Stats/AP_Stats.cpp +++ b/libraries/AP_Stats/AP_Stats.cpp @@ -76,6 +76,7 @@ void AP_Stats::flush() void AP_Stats::update_flighttime() { if (_flying_ms) { + WITH_SEMAPHORE(sem); const uint32_t now = AP_HAL::millis(); const uint32_t delta = (now - _flying_ms)/1000; flttime += delta; @@ -93,6 +94,7 @@ void AP_Stats::update_runtime() void AP_Stats::update() { + WITH_SEMAPHORE(sem); const uint32_t now_ms = AP_HAL::millis(); if (now_ms - last_flush_ms > flush_interval_ms) { update_flighttime(); diff --git a/libraries/AP_Stats/AP_Stats.h b/libraries/AP_Stats/AP_Stats.h index d940ea46c0..e20ad0d597 100644 --- a/libraries/AP_Stats/AP_Stats.h +++ b/libraries/AP_Stats/AP_Stats.h @@ -67,7 +67,7 @@ private: void update_flighttime(); void update_runtime(); - + HAL_Semaphore_Recursive sem; }; namespace AP {