From 97d4df41542ee64adb65e94414c2d34876edfc1e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 2 Oct 2022 19:30:43 +0100 Subject: [PATCH] Better thread safety for zone boundingbox caches. --- pcbnew/board.h | 1 - pcbnew/board_design_settings.cpp | 2 +- pcbnew/zone.cpp | 13 ++++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pcbnew/board.h b/pcbnew/board.h index 5ff56af6b6..aeeb7e5408 100644 --- a/pcbnew/board.h +++ b/pcbnew/board.h @@ -1151,7 +1151,6 @@ public: std::unordered_map< wxString, LSET > m_LayerExpressionCache; std::unordered_map> m_CopperZoneRTreeCache; std::unique_ptr m_CopperItemRTreeCache; - mutable std::unordered_map m_ZoneBBoxCache; // ------------ DRC caches ------------- diff --git a/pcbnew/board_design_settings.cpp b/pcbnew/board_design_settings.cpp index 944d842ca7..59427d82ab 100644 --- a/pcbnew/board_design_settings.cpp +++ b/pcbnew/board_design_settings.cpp @@ -181,7 +181,7 @@ BOARD_DESIGN_SETTINGS::BOARD_DESIGN_SETTINGS( JSON_SETTINGS* aParent, const std: m_DRCSeverities[ DRCE_TEXT_THICKNESS ] = RPT_SEVERITY_WARNING; m_DRCSeverities[ DRCE_FOOTPRINT_TYPE_MISMATCH ] = RPT_SEVERITY_IGNORE; - + m_DRCSeverities[ DRCE_LIB_FOOTPRINT_ISSUES ] = RPT_SEVERITY_WARNING; m_DRCSeverities[ DRCE_LIB_FOOTPRINT_MISMATCH ] = RPT_SEVERITY_WARNING; diff --git a/pcbnew/zone.cpp b/pcbnew/zone.cpp index 8f95f0a369..0c16a5bfd1 100644 --- a/pcbnew/zone.cpp +++ b/pcbnew/zone.cpp @@ -308,16 +308,19 @@ bool ZONE::IsOnLayer( PCB_LAYER_ID aLayer ) const const BOX2I ZONE::GetBoundingBox() const { - if( const BOARD* parent = GetBoard() ) + if( const BOARD* board = GetBoard() ) { - std::unordered_map& cache = parent->m_ZoneBBoxCache; + std::unordered_map& cache = board->m_ZoneBBoxCache; auto cacheIter = cache.find( this ); if( cacheIter != cache.end() ) return cacheIter->second; BOX2I bbox = m_Poly->BBox(); + + std::unique_lock cacheLock( const_cast( board )->m_CachesMutex ); cache[ this ] = bbox; + return bbox; } @@ -327,12 +330,16 @@ const BOX2I ZONE::GetBoundingBox() const void ZONE::CacheBoundingBox() { - std::unordered_map& cache = GetBoard()->m_ZoneBBoxCache; + BOARD* board = GetBoard(); + std::unordered_map& cache = board->m_ZoneBBoxCache; auto cacheIter = cache.find( this ); if( cacheIter == cache.end() ) + { + std::unique_lock cacheLock( board->m_CachesMutex ); cache[ this ] = m_Poly->BBox(); + } }