Split connectivity mutex locking

Internal routines have no need for locking the mutex they already own.
While external routines that want to recalculate the Ratsnest do need an
exclusive lock before being allowed access

Fixes https://gitlab.com/kicad/code/kicad/issues/13011
This commit is contained in:
Seth Hillbrand 2023-02-03 15:22:36 +01:00
parent 8ce0a84ca7
commit dde336ee40
2 changed files with 16 additions and 7 deletions

View File

@ -128,7 +128,7 @@ bool CONNECTIVITY_DATA::Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
aReporter->KeepRefreshing( false );
}
RecalculateRatsnest();
internalRecalculateRatsnest();
if( aReporter )
{
@ -150,7 +150,7 @@ void CONNECTIVITY_DATA::Build( const std::vector<BOARD_ITEM*>& aItems )
m_connAlgo.reset( new CN_CONNECTIVITY_ALGO );
m_connAlgo->LocalBuild( aItems );
RecalculateRatsnest();
internalRecalculateRatsnest();
}
@ -208,11 +208,14 @@ void CONNECTIVITY_DATA::RecalculateRatsnest( BOARD_COMMIT* aCommit )
// We can take over the lock here if called in the same thread
// This is to prevent redraw during a RecalculateRatsnets process
std::unique_lock<KISPINLOCK> lock( m_lock, std::adopt_lock );
std::unique_lock<KISPINLOCK> lock( m_lock );
if( !lock )
return;
internalRecalculateRatsnest( aCommit );
}
void CONNECTIVITY_DATA::internalRecalculateRatsnest( BOARD_COMMIT* aCommit )
{
m_connAlgo->PropagateNets( aCommit );
int lastNet = m_connAlgo->NetCount();

View File

@ -295,9 +295,15 @@ public:
std::shared_ptr<FROM_TO_CACHE> GetFromToCache() { return m_fromToCache; }
private:
void updateRatsnest();
void addRatsnestCluster( const std::shared_ptr<CN_CLUSTER>& aCluster );
/**
* Updates the ratsnest for the board without locking the connectivity mutex.
* @param aCommit is used to save the undo state of items modified by this call
*/
void internalRecalculateRatsnest( BOARD_COMMIT* aCommit = nullptr );
void updateRatsnest();
void addRatsnestCluster( const std::shared_ptr<CN_CLUSTER>& aCluster );
private:
std::shared_ptr<CN_CONNECTIVITY_ALGO> m_connAlgo;