diff --git a/scwx-qt/source/scwx/qt/map/alert_layer.cpp b/scwx-qt/source/scwx/qt/map/alert_layer.cpp index 81379562..77563d5f 100644 --- a/scwx-qt/source/scwx/qt/map/alert_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/alert_layer.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -86,7 +87,8 @@ class AlertLayerHandler : public QObject bool, std::list::iterator>, types::TextEventHash> - featureMap_; + featureMap_; + std::shared_mutex alertMutex_; signals: void AlertsUpdated(awips::Phenomenon phenomenon, bool alertActive); @@ -251,6 +253,9 @@ void AlertLayerHandler::HandleAlert(const types::TextEventKey& key, AlertTypeHash>> alertsUpdated {}; + // Take a unique lock before modifying feature lists + std::unique_lock lock(alertMutex_); + // Remove existing features for key auto existingFeatures = featureMap_.equal_range(key); for (auto it = existingFeatures.first; it != existingFeatures.second; ++it) @@ -299,6 +304,9 @@ void AlertLayerHandler::HandleAlert(const types::TextEventKey& key, } } + // Release the lock after completing feature list updates + lock.unlock(); + for (auto& alert : alertsUpdated) { // Emit signal for each updated alert type @@ -315,10 +323,15 @@ void AlertLayerImpl::UpdateSource(awips::Phenomenon phenomenon, return; } + auto& alertLayerHandler = AlertLayerHandler::Instance(); + + // Take a shared lock before using feature lists + std::shared_lock lock(alertLayerHandler.alertMutex_); + // Update source, relies on alert source being defined map->updateSource( QString("alertPolygon-%1").arg(GetSuffix(phenomenon, alertActive)), - AlertLayerHandler::Instance().alertSourceMap_.at( + alertLayerHandler.alertSourceMap_.at( std::make_pair(phenomenon, alertActive))); }