mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-30 17:00:05 +00:00 
			
		
		
		
	Create sweep mutex to eliminate race condition between ComputeSweep() and UpdateSweep()
This commit is contained in:
		
							parent
							
								
									b2fbfa0dee
								
							
						
					
					
						commit
						4c6a40140b
					
				
					 4 changed files with 26 additions and 5 deletions
				
			
		|  | @ -148,8 +148,6 @@ void RadarProductLayer::UpdateSweep() | |||
| { | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "UpdateSweep()"; | ||||
| 
 | ||||
|    p->sweepNeedsUpdate_ = false; | ||||
| 
 | ||||
|    gl::OpenGLFunctions& gl = context()->gl_; | ||||
| 
 | ||||
|    boost::timer::cpu_timer timer; | ||||
|  | @ -157,6 +155,17 @@ void RadarProductLayer::UpdateSweep() | |||
|    std::shared_ptr<view::RadarProductView> radarProductView = | ||||
|       context()->radarProductView_; | ||||
| 
 | ||||
|    std::unique_lock sweepLock(radarProductView->sweep_mutex(), | ||||
|                               std::try_to_lock); | ||||
|    if (!sweepLock.owns_lock()) | ||||
|    { | ||||
|       BOOST_LOG_TRIVIAL(debug) | ||||
|          << logPrefix_ << "Sweep locked, deferring update"; | ||||
|       return; | ||||
|    } | ||||
| 
 | ||||
|    p->sweepNeedsUpdate_ = false; | ||||
| 
 | ||||
|    const std::vector<float>& vertices = radarProductView->vertices(); | ||||
| 
 | ||||
|    // Bind a vertex array object
 | ||||
|  |  | |||
|  | @ -353,6 +353,8 @@ void Level2ProductView::ComputeSweep() | |||
|       return; | ||||
|    } | ||||
| 
 | ||||
|    std::scoped_lock sweepLock(sweep_mutex()); | ||||
| 
 | ||||
|    std::shared_ptr<wsr88d::rda::ElevationScan> radarData; | ||||
|    std::tie(radarData, p->elevationCut_, p->elevationCuts_) = | ||||
|       p->radarProductManager_->GetLevel2Data( | ||||
|  |  | |||
|  | @ -24,8 +24,10 @@ static const uint16_t DEFAULT_COLOR_TABLE_MAX = 255u; | |||
| class RadarProductViewImpl | ||||
| { | ||||
| public: | ||||
|    explicit RadarProductViewImpl() = default; | ||||
|    explicit RadarProductViewImpl() : sweepMutex_ {} {} | ||||
|    ~RadarProductViewImpl() = default; | ||||
| 
 | ||||
|    std::mutex sweepMutex_; | ||||
| }; | ||||
| 
 | ||||
| RadarProductView::RadarProductView() : | ||||
|  | @ -63,6 +65,11 @@ std::chrono::system_clock::time_point RadarProductView::sweep_time() const | |||
|    return {}; | ||||
| } | ||||
| 
 | ||||
| std::mutex& RadarProductView::sweep_mutex() | ||||
| { | ||||
|    return p->sweepMutex_; | ||||
| } | ||||
| 
 | ||||
| void RadarProductView::Initialize() | ||||
| { | ||||
|    ComputeSweep(); | ||||
|  |  | |||
|  | @ -5,6 +5,7 @@ | |||
| 
 | ||||
| #include <chrono> | ||||
| #include <memory> | ||||
| #include <mutex> | ||||
| #include <vector> | ||||
| 
 | ||||
| #include <QObject> | ||||
|  | @ -35,6 +36,8 @@ public: | |||
|    virtual uint16_t                              vcp() const      = 0; | ||||
|    virtual const std::vector<float>&             vertices() const = 0; | ||||
| 
 | ||||
|    std::mutex& sweep_mutex(); | ||||
| 
 | ||||
|    void Initialize(); | ||||
|    virtual void | ||||
|    LoadColorTable(std::shared_ptr<common::ColorTable> colorTable) = 0; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat