From 4609bba178257e4dec9696bcced3a0f9e5326f67 Mon Sep 17 00:00:00 2001 From: Folke Will Date: Sun, 4 Nov 2018 11:27:21 +0100 Subject: [PATCH] Remove -latomic dependency because Linux gcc loads that at runtime --- src/CMakeLists.txt | 1 - src/environment/xplane/XPlaneEnvironment.cpp | 9 +++++++-- src/environment/xplane/XPlaneEnvironment.h | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bdccacfa..5f01390d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,7 +38,6 @@ target_link_libraries(avitab_common if(WIN32) target_link_libraries(avitab_common - atomic ws2_32 ) endif(WIN32) diff --git a/src/environment/xplane/XPlaneEnvironment.cpp b/src/environment/xplane/XPlaneEnvironment.cpp index 466555d0..5a472810 100644 --- a/src/environment/xplane/XPlaneEnvironment.cpp +++ b/src/environment/xplane/XPlaneEnvironment.cpp @@ -252,7 +252,11 @@ float XPlaneEnvironment::onFlightLoop(float elapsedSinceLastCall, float elapseSi loc.latitude = dataCache.getData("sim/flightmodel/position/latitude").doubleValue; loc.longitude = dataCache.getData("sim/flightmodel/position/longitude").doubleValue; loc.heading = dataCache.getData("sim/flightmodel/position/psi").floatValue; - aircraftLocation.store(loc); + + { + std::lock_guard lock(stateMutex); + aircraftLocation = loc; + } lastDrawTime = dataCache.getData("sim/operation/misc/frame_rate_period").floatValue; @@ -261,7 +265,8 @@ float XPlaneEnvironment::onFlightLoop(float elapsedSinceLastCall, float elapseSi } Location XPlaneEnvironment::getAircraftLocation() { - return aircraftLocation.load(); + std::lock_guard lock(stateMutex); + return aircraftLocation; } float XPlaneEnvironment::getLastFrameTime() { diff --git a/src/environment/xplane/XPlaneEnvironment.h b/src/environment/xplane/XPlaneEnvironment.h index b178c9dc..fb268a69 100644 --- a/src/environment/xplane/XPlaneEnvironment.h +++ b/src/environment/xplane/XPlaneEnvironment.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "src/gui_toolkit/LVGLToolkit.h" #include "src/environment/Environment.h" #include "DataCache.h" @@ -68,10 +69,11 @@ class XPlaneEnvironment: public Environment { DataCache dataCache; std::string pluginPath, xplaneRootPath; std::shared_ptr xplaneData; - std::atomic aircraftLocation{}; + Location aircraftLocation{}; std::atomic lastDrawTime{}; // State + std::mutex stateMutex; std::vector menuCallbacks; std::atomic flightLoopId { nullptr }; std::map commandHandlers;