[tracks] Safe GpsTrackCollection requests during recording.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
Viktor Govako
2025-07-30 15:27:29 -03:00
committed by Konstantin Pastbin
parent fb62982000
commit b7b87f5530
4 changed files with 13 additions and 8 deletions

View File

@@ -50,15 +50,20 @@ void GpsTrack::AddPoints(vector<location::GpsInfo> const & points)
ScheduleTask();
}
TrackStatistics GpsTrack::GetTrackStatistics() const
/// @note These functions are called during recording, so should be synchronized with Collection writer thread.
/// @{
TrackStatistics GpsTrack::GetTrackStatistics()
{
lock_guard<mutex> lg(m_threadGuard);
return m_collection ? m_collection->GetTrackStatistics() : TrackStatistics();
}
ElevationInfo const & GpsTrack::GetElevationInfo() const
ElevationInfo const & GpsTrack::GetElevationInfo()
{
lock_guard<mutex> lg(m_threadGuard);
return m_collection->UpdateAndGetElevationInfo();
}
/// @}
void GpsTrack::Clear()
{

View File

@@ -31,8 +31,8 @@ public:
void AddPoints(std::vector<location::GpsInfo> const & points);
/// Returns track statistics
TrackStatistics GetTrackStatistics() const;
ElevationInfo const & GetElevationInfo() const;
TrackStatistics GetTrackStatistics();
ElevationInfo const & GetElevationInfo();
/// Clears any previous tracking info
/// @note Callback is called with 'toRemove' points, if some points were removed.

View File

@@ -68,12 +68,12 @@ bool GpsTracker::IsEmpty() const
return m_track.IsEmpty();
}
TrackStatistics GpsTracker::GetTrackStatistics() const
TrackStatistics GpsTracker::GetTrackStatistics()
{
return m_track.GetTrackStatistics();
}
ElevationInfo const & GpsTracker::GetElevationInfo() const
ElevationInfo const & GpsTracker::GetElevationInfo()
{
return m_track.GetElevationInfo();
}

View File

@@ -17,8 +17,8 @@ public:
bool IsEmpty() const;
TrackStatistics GetTrackStatistics() const;
ElevationInfo const & GetElevationInfo() const;
TrackStatistics GetTrackStatistics();
ElevationInfo const & GetElevationInfo();
using TGpsTrackDiffCallback =
std::function<void(std::vector<std::pair<size_t, location::GpsInfo>> && toAdd,