When garbage collecting locally we also need to clear global references.

This commit is contained in:
Jeff Young 2023-11-01 12:47:42 +00:00
parent bc42546609
commit d93bb464bf
6 changed files with 45 additions and 18 deletions

View File

@ -223,6 +223,12 @@ void CN_CONNECTIVITY_ALGO::searchConnections()
m_itemList.RemoveInvalidItems( garbage );
if( m_isLocal )
{
for( CN_ITEM* item : m_globalConnectivity->m_itemList )
item->RemoveInvalidRefs();
}
for( CN_ITEM* item : garbage )
delete item;
@ -553,9 +559,13 @@ void CN_CONNECTIVITY_ALGO::Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
}
void CN_CONNECTIVITY_ALGO::LocalBuild( const std::vector<BOARD_ITEM*>& aItems )
void CN_CONNECTIVITY_ALGO::LocalBuild( std::shared_ptr<CN_CONNECTIVITY_ALGO> aGlobalConnectivity,
const std::vector<BOARD_ITEM*>& aLocalItems )
{
for( BOARD_ITEM* item : aItems )
m_isLocal = true;
m_globalConnectivity = aGlobalConnectivity;
for( BOARD_ITEM* item : aLocalItems )
{
switch( item->Type() )
{

View File

@ -158,8 +158,14 @@ public:
std::list<CN_ITEM*> m_items;
};
CN_CONNECTIVITY_ALGO() {}
~CN_CONNECTIVITY_ALGO() { Clear(); }
CN_CONNECTIVITY_ALGO() :
m_isLocal( false )
{}
~CN_CONNECTIVITY_ALGO()
{
Clear();
}
bool ItemExists( const BOARD_CONNECTED_ITEM* aItem ) const
{
@ -201,8 +207,9 @@ public:
return m_dirtyNets.size();
}
void Build( BOARD* aZoneLayer, PROGRESS_REPORTER* aReporter = nullptr );
void LocalBuild( const std::vector<BOARD_ITEM*>& aItems );
void Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter = nullptr );
void LocalBuild( std::shared_ptr<CN_CONNECTIVITY_ALGO> aGlobalConnectivity,
const std::vector<BOARD_ITEM*>& aLocalItems );
void Clear();
@ -276,6 +283,9 @@ private:
std::vector<std::shared_ptr<CN_CLUSTER>> m_ratsnestClusters;
std::vector<bool> m_dirtyNets;
bool m_isLocal;
std::shared_ptr<CN_CONNECTIVITY_ALGO> m_globalConnectivity;
PROGRESS_REPORTER* m_progressReporter = nullptr;
};

View File

@ -44,7 +44,8 @@
#include <trigo.h>
#include <drc/drc_rtree.h>
CONNECTIVITY_DATA::CONNECTIVITY_DATA()
CONNECTIVITY_DATA::CONNECTIVITY_DATA() :
m_skipRatsnestUpdate( false )
{
m_connAlgo.reset( new CN_CONNECTIVITY_ALGO );
m_progressReporter = nullptr;
@ -52,10 +53,12 @@ CONNECTIVITY_DATA::CONNECTIVITY_DATA()
}
CONNECTIVITY_DATA::CONNECTIVITY_DATA( const std::vector<BOARD_ITEM*>& aItems, bool aSkipRatsnest )
: m_skipRatsnest( aSkipRatsnest )
CONNECTIVITY_DATA::CONNECTIVITY_DATA( std::shared_ptr<CONNECTIVITY_DATA> aGlobalConnectivity,
const std::vector<BOARD_ITEM*>& aLocalItems,
bool aSkipRatsnestUpdate ) :
m_skipRatsnestUpdate( aSkipRatsnestUpdate )
{
Build( aItems );
Build( aGlobalConnectivity, aLocalItems );
m_progressReporter = nullptr;
m_fromToCache.reset( new FROM_TO_CACHE );
}
@ -140,7 +143,8 @@ bool CONNECTIVITY_DATA::Build( BOARD* aBoard, PROGRESS_REPORTER* aReporter )
}
void CONNECTIVITY_DATA::Build( const std::vector<BOARD_ITEM*>& aItems )
void CONNECTIVITY_DATA::Build( std::shared_ptr<CONNECTIVITY_DATA>& aGlobalConnectivity,
const std::vector<BOARD_ITEM*>& aLocalItems )
{
std::unique_lock<KISPINLOCK> lock( m_lock, std::try_to_lock );
@ -148,7 +152,7 @@ void CONNECTIVITY_DATA::Build( const std::vector<BOARD_ITEM*>& aItems )
return;
m_connAlgo.reset( new CN_CONNECTIVITY_ALGO );
m_connAlgo->LocalBuild( aItems );
m_connAlgo->LocalBuild( aGlobalConnectivity->GetConnectivityAlgo(), aLocalItems );
internalRecalculateRatsnest();
}
@ -272,7 +276,7 @@ void CONNECTIVITY_DATA::internalRecalculateRatsnest( BOARD_COMMIT* aCommit )
m_connAlgo->ClearDirtyFlags();
if( !m_skipRatsnest )
if( !m_skipRatsnestUpdate )
updateRatsnest();
}

View File

@ -89,7 +89,8 @@ public:
CONNECTIVITY_DATA();
~CONNECTIVITY_DATA();
CONNECTIVITY_DATA( const std::vector<BOARD_ITEM*>& aItems, bool aSkipItems = false );
CONNECTIVITY_DATA( std::shared_ptr<CONNECTIVITY_DATA> aGlobalConnectivity,
const std::vector<BOARD_ITEM*>& aLocalItems, bool aSkipRatsnestUpdate = false );
/**
* Function Build()
@ -101,7 +102,8 @@ public:
* Function Build()
* Builds the connectivity database for a set of items aItems.
*/
void Build( const std::vector<BOARD_ITEM*>& aItems );
void Build( std::shared_ptr<CONNECTIVITY_DATA>& aGlobalConnectivity,
const std::vector<BOARD_ITEM*>& aLocalItems );
/**
* Function Add()
@ -300,7 +302,7 @@ private:
std::vector<RN_NET*> m_nets;
/// Used to suppress ratsnest calculations on dynamic ratsnests
bool m_skipRatsnest = false;
bool m_skipRatsnestUpdate;
KISPINLOCK m_lock;

View File

@ -2175,7 +2175,8 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent )
courtyardClearanceDRC.m_FpInMove.push_back( footprint );
}
dynamicData = std::make_unique<CONNECTIVITY_DATA>( dynamicItems, true );
dynamicData = std::make_unique<CONNECTIVITY_DATA>( board()->GetConnectivity(),
dynamicItems, true );
connectivityData->BlockRatsnestItems( dynamicItems );
}
else

View File

@ -1974,7 +1974,7 @@ void BOARD_INSPECTION_TOOL::calculateSelectionRatsnest( const VECTOR2I& aDelta )
if( !m_dynamicData )
{
m_dynamicData = new CONNECTIVITY_DATA( items, true );
m_dynamicData = new CONNECTIVITY_DATA( board()->GetConnectivity(), items, true );
connectivity->BlockRatsnestItems( items );
}
else