Better thread safety for zone boundingbox caches.

This commit is contained in:
Jeff Young 2022-10-02 19:30:43 +01:00
parent adbbceacda
commit 97d4df4154
3 changed files with 11 additions and 5 deletions

View File

@ -1151,7 +1151,6 @@ public:
std::unordered_map< wxString, LSET > m_LayerExpressionCache;
std::unordered_map<ZONE*, std::unique_ptr<DRC_RTREE>> m_CopperZoneRTreeCache;
std::unique_ptr<DRC_RTREE> m_CopperItemRTreeCache;
mutable std::unordered_map<const ZONE*, BOX2I> m_ZoneBBoxCache;
// ------------ DRC caches -------------

View File

@ -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;

View File

@ -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<const ZONE*, BOX2I>& cache = parent->m_ZoneBBoxCache;
std::unordered_map<const ZONE*, BOX2I>& cache = board->m_ZoneBBoxCache;
auto cacheIter = cache.find( this );
if( cacheIter != cache.end() )
return cacheIter->second;
BOX2I bbox = m_Poly->BBox();
std::unique_lock<std::mutex> cacheLock( const_cast<BOARD*>( board )->m_CachesMutex );
cache[ this ] = bbox;
return bbox;
}
@ -327,12 +330,16 @@ const BOX2I ZONE::GetBoundingBox() const
void ZONE::CacheBoundingBox()
{
std::unordered_map<const ZONE*, BOX2I>& cache = GetBoard()->m_ZoneBBoxCache;
BOARD* board = GetBoard();
std::unordered_map<const ZONE*, BOX2I>& cache = board->m_ZoneBBoxCache;
auto cacheIter = cache.find( this );
if( cacheIter == cache.end() )
{
std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
cache[ this ] = m_Poly->BBox();
}
}