From dff78f8961610bf72afd7b82b0baa73487b41ec2 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 14 Jul 2025 10:13:58 +0100 Subject: [PATCH] Thread safety. (cherry picked from commit 80c447f869c0b87edcb853bc8040921c7755ed2d) --- pcbnew/tools/zone_filler_tool.cpp | 21 +++++++++------------ pcbnew/zone_filler.cpp | 9 ++++++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pcbnew/tools/zone_filler_tool.cpp b/pcbnew/tools/zone_filler_tool.cpp index 33a3eb01ea..ea9630402c 100644 --- a/pcbnew/tools/zone_filler_tool.cpp +++ b/pcbnew/tools/zone_filler_tool.cpp @@ -140,8 +140,7 @@ void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller, PROGRESS_REPORTER* aRepo if( !board()->GetDesignSettings().m_DRCEngine->RulesValid() ) { WX_INFOBAR* infobar = frame->GetInfoBar(); - wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, _( "Show DRC rules" ), - wxEmptyString ); + wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, _( "Show DRC rules" ), wxEmptyString ); button->Bind( wxEVT_COMMAND_HYPERLINK, std::function( @@ -153,8 +152,8 @@ void ZONE_FILLER_TOOL::FillAllZones( wxWindow* aCaller, PROGRESS_REPORTER* aRepo infobar->RemoveAllButtons(); infobar->AddButton( button ); - infobar->ShowMessageFor( _( "Zone fills may be inaccurate. DRC rules contain errors." ), - 10000, wxICON_WARNING ); + infobar->ShowMessageFor( _( "Zone fills may be inaccurate. DRC rules contain errors." ), 10000, + wxICON_WARNING ); } if( aReporter ) @@ -227,8 +226,7 @@ int ZONE_FILLER_TOOL::ZoneFillDirty( const TOOL_EVENT& aEvent ) if( !board()->GetDesignSettings().m_DRCEngine->RulesValid() ) { WX_INFOBAR* infobar = frame->GetInfoBar(); - wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, _( "Show DRC rules" ), - wxEmptyString ); + wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, _( "Show DRC rules" ), wxEmptyString ); button->Bind( wxEVT_COMMAND_HYPERLINK, std::function( @@ -240,8 +238,8 @@ int ZONE_FILLER_TOOL::ZoneFillDirty( const TOOL_EVENT& aEvent ) infobar->RemoveAllButtons(); infobar->AddButton( button ); - infobar->ShowMessageFor( _( "Zone fills may be inaccurate. DRC rules contain errors." ), - 10000, wxICON_WARNING ); + infobar->ShowMessageFor( _( "Zone fills may be inaccurate. DRC rules contain errors." ), 10000, + wxICON_WARNING ); } for( ZONE* zone : toFill ) @@ -280,14 +278,13 @@ int ZONE_FILLER_TOOL::ZoneFillDirty( const TOOL_EVENT& aEvent ) button->Bind( wxEVT_COMMAND_HYPERLINK, std::function( [this]( wxHyperlinkEvent& ) { - getEditFrame()->ShowPreferences( _( "Editing Options" ), - _( "PCB Editor" ) ); + getEditFrame()->ShowPreferences( _( "Editing Options" ), _( "PCB Editor" ) ); } ) ); infobar->RemoveAllButtons(); infobar->AddButton( button ); - infobar->ShowMessageFor( _( "Automatic refill of zones can be turned off in Preferences " - "if it becomes too slow." ), + infobar->ShowMessageFor( _( "Automatic refill of zones can be turned off in Preferences if it becomes " + "too slow." ), 10000, wxICON_INFORMATION, WX_INFOBAR::MESSAGE_TYPE::GENERIC ); } diff --git a/pcbnew/zone_filler.cpp b/pcbnew/zone_filler.cpp index 07a34d704b..35eb8a1e99 100644 --- a/pcbnew/zone_filler.cpp +++ b/pcbnew/zone_filler.cpp @@ -194,7 +194,7 @@ private: }; -ZONE_FILLER::ZONE_FILLER( BOARD* aBoard, COMMIT* aCommit ) : +ZONE_FILLER::ZONE_FILLER( BOARD* aBoard, COMMIT* aCommit ) : m_board( aBoard ), m_brdOutlinesValid( false ), m_commit( aCommit ), @@ -215,8 +215,7 @@ ZONE_FILLER::~ZONE_FILLER() void ZONE_FILLER::SetProgressReporter( PROGRESS_REPORTER* aReporter ) { m_progressReporter = aReporter; - wxASSERT_MSG( m_commit, wxT( "ZONE_FILLER must have a valid commit to call " - "SetProgressReporter" ) ); + wxASSERT_MSG( m_commit, wxT( "ZONE_FILLER must have a valid commit to call SetProgressReporter" ) ); } @@ -240,6 +239,10 @@ bool ZONE_FILLER::Fill( const std::vector& aZones, bool aCheck, wxWindow* std::shared_ptr connectivity = m_board->GetConnectivity(); + // Ensure that multiple threads don't attempt to initialize the advanced cfg global at the same + // time. + ADVANCED_CFG::GetCfg(); + // Rebuild (from scratch, ignoring dirty flags) just in case. This really needs to be reliable. connectivity->ClearRatsnest(); connectivity->Build( m_board, m_progressReporter );