mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 13:10:04 +00:00 
			
		
		
		
	Add alert layer mutex
This commit is contained in:
		
							parent
							
								
									c87a77795d
								
							
						
					
					
						commit
						c418995682
					
				
					 1 changed files with 15 additions and 2 deletions
				
			
		|  | @ -2,6 +2,7 @@ | ||||||
| #include <scwx/qt/manager/text_event_manager.hpp> | #include <scwx/qt/manager/text_event_manager.hpp> | ||||||
| #include <scwx/util/logger.hpp> | #include <scwx/util/logger.hpp> | ||||||
| 
 | 
 | ||||||
|  | #include <shared_mutex> | ||||||
| #include <unordered_set> | #include <unordered_set> | ||||||
| 
 | 
 | ||||||
| #include <boost/container_hash/hash.hpp> | #include <boost/container_hash/hash.hpp> | ||||||
|  | @ -87,6 +88,7 @@ class AlertLayerHandler : public QObject | ||||||
|                  std::list<QMapLibreGL::Feature>::iterator>, |                  std::list<QMapLibreGL::Feature>::iterator>, | ||||||
|       types::TextEventHash<types::TextEventKey>> |       types::TextEventHash<types::TextEventKey>> | ||||||
|                      featureMap_; |                      featureMap_; | ||||||
|  |    std::shared_mutex alertMutex_; | ||||||
| 
 | 
 | ||||||
| signals: | signals: | ||||||
|    void AlertsUpdated(awips::Phenomenon phenomenon, bool alertActive); |    void AlertsUpdated(awips::Phenomenon phenomenon, bool alertActive); | ||||||
|  | @ -251,6 +253,9 @@ void AlertLayerHandler::HandleAlert(const types::TextEventKey& key, | ||||||
|                       AlertTypeHash<std::pair<awips::Phenomenon, bool>>> |                       AlertTypeHash<std::pair<awips::Phenomenon, bool>>> | ||||||
|       alertsUpdated {}; |       alertsUpdated {}; | ||||||
| 
 | 
 | ||||||
|  |    // Take a unique lock before modifying feature lists
 | ||||||
|  |    std::unique_lock lock(alertMutex_); | ||||||
|  | 
 | ||||||
|    // Remove existing features for key
 |    // Remove existing features for key
 | ||||||
|    auto existingFeatures = featureMap_.equal_range(key); |    auto existingFeatures = featureMap_.equal_range(key); | ||||||
|    for (auto it = existingFeatures.first; it != existingFeatures.second; ++it) |    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) |    for (auto& alert : alertsUpdated) | ||||||
|    { |    { | ||||||
|       // Emit signal for each updated alert type
 |       // Emit signal for each updated alert type
 | ||||||
|  | @ -315,10 +323,15 @@ void AlertLayerImpl::UpdateSource(awips::Phenomenon phenomenon, | ||||||
|       return; |       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
 |    // Update source, relies on alert source being defined
 | ||||||
|    map->updateSource( |    map->updateSource( | ||||||
|       QString("alertPolygon-%1").arg(GetSuffix(phenomenon, alertActive)), |       QString("alertPolygon-%1").arg(GetSuffix(phenomenon, alertActive)), | ||||||
|       AlertLayerHandler::Instance().alertSourceMap_.at( |       alertLayerHandler.alertSourceMap_.at( | ||||||
|          std::make_pair(phenomenon, alertActive))); |          std::make_pair(phenomenon, alertActive))); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat