Multi-threading safety.

(Possible fix for KICAD-74.)

(cherry picked from commit b76ef8c7e2)
This commit is contained in:
Jeff Young 2023-04-16 15:35:58 +01:00
parent 3217372720
commit f3db64af05
3 changed files with 19 additions and 14 deletions

View File

@ -182,13 +182,21 @@ void CONNECTIVITY_DATA::updateRatsnest()
thread_pool& tp = GetKiCadThreadPool();
tp.push_loop( dirty_nets.size(),
[&]( const int a, const int b)
[&]( const int a, const int b )
{
for( int ii = a; ii < b; ++ii )
dirty_nets[ii]->UpdateNet();
} );
tp.wait_for_tasks();
tp.push_loop( dirty_nets.size(),
[&]( const int a, const int b )
{
for( int ii = a; ii < b; ++ii )
dirty_nets[ii]->OptimizeRNEdges();
} );
tp.wait_for_tasks();
#ifdef PROFILE
rnUpdate.Show();
#endif

View File

@ -328,7 +328,7 @@ void RN_NET::compute()
}
void RN_NET::optimizeRNEdges()
void RN_NET::OptimizeRNEdges()
{
auto optimizeZoneAnchor =
[&]( const VECTOR2I& aPos, const LSET& aLayerSet,
@ -448,14 +448,6 @@ void RN_NET::UpdateNet()
{
compute();
#ifdef PROFILE
PROF_TIMER cnt( "optimize" );
#endif
optimizeRNEdges();
#ifdef PROFILE
cnt.Show();
#endif
m_dirty = false;
}

View File

@ -76,6 +76,15 @@ public:
* Recompute ratsnest for a net.
*/
void UpdateNet();
/**
* Find optimal ends of RNEdges. The MST will have found the closest anchors, but when
* zones are involved we might have points closer than the anchors.
*
* Normally called after UpdateNet(), but from a separate multi-threaded loop for safety.
*/
void OptimizeRNEdges();
void Clear();
void AddCluster( std::shared_ptr<CN_CLUSTER> aCluster );
@ -94,10 +103,6 @@ protected:
///< Compute the minimum spanning tree using Kruskal's algorithm
void kruskalMST( const std::vector<CN_EDGE> &aEdges );
///< Find optimal ends of RNEdges. The MST will have found the closest anchors, but when
///< zones are involved we might have points closer than the anchors.
void optimizeRNEdges();
protected:
///< Vector of nodes
std::multiset<std::shared_ptr<CN_ANCHOR>, CN_PTR_CMP> m_nodes;