Use lock when clearing and loading libTables.

Also make sure it's re-indexed after loading.
This commit is contained in:
Jeff Young 2024-07-21 17:37:45 +01:00
parent e2bd76bdce
commit 0f099ac65e
8 changed files with 14 additions and 30 deletions

View File

@ -607,7 +607,6 @@ bool FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable )
} }
} }
aTable.Clear();
aTable.Load( fn.GetFullPath() ); aTable.Load( fn.GetFullPath() );
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();

View File

@ -128,7 +128,7 @@ LIB_TABLE::~LIB_TABLE()
} }
void LIB_TABLE::Clear() void LIB_TABLE::clear()
{ {
m_rows.clear(); m_rows.clear();
m_rowsMap.clear(); m_rowsMap.clear();
@ -406,6 +406,7 @@ void LIB_TABLE::TransferRows( LIB_TABLE_ROWS& aRowsList )
{ {
std::lock_guard<std::shared_mutex> lock( m_mutex ); std::lock_guard<std::shared_mutex> lock( m_mutex );
clear();
m_rows.transfer( m_rows.end(), aRowsList.begin(), aRowsList.end(), aRowsList ); m_rows.transfer( m_rows.end(), aRowsList.begin(), aRowsList.end(), aRowsList );
reindex(); reindex();
@ -451,6 +452,9 @@ bool LIB_TABLE::migrate()
void LIB_TABLE::Load( const wxString& aFileName ) void LIB_TABLE::Load( const wxString& aFileName )
{ {
std::shared_lock<std::shared_mutex> lock( m_mutex );
clear();
// It's OK if footprint library tables are missing. // It's OK if footprint library tables are missing.
if( wxFileName::IsFileReadable( aFileName ) ) if( wxFileName::IsFileReadable( aFileName ) )
{ {
@ -461,6 +465,8 @@ void LIB_TABLE::Load( const wxString& aFileName )
if( m_version != 7 && migrate() && wxFileName::IsFileWritable( aFileName ) ) if( m_version != 7 && migrate() && wxFileName::IsFileWritable( aFileName ) )
Save( aFileName ); Save( aFileName );
reindex();
} }
} }

View File

@ -1014,16 +1014,12 @@ bool PANEL_SYM_LIB_TABLE::TransferDataFromWindow()
if( *global_model() != *m_globalTable ) if( *global_model() != *m_globalTable )
{ {
m_parent->m_GlobalTableChanged = true; m_parent->m_GlobalTableChanged = true;
m_globalTable->Clear();
m_globalTable->TransferRows( global_model()->m_rows ); m_globalTable->TransferRows( global_model()->m_rows );
} }
if( project_model() && *project_model() != *m_projectTable ) if( project_model() && *project_model() != *m_projectTable )
{ {
m_parent->m_ProjectTableChanged = true; m_parent->m_ProjectTableChanged = true;
m_projectTable->Clear();
m_projectTable->TransferRows( project_model()->m_rows ); m_projectTable->TransferRows( project_model()->m_rows );
} }

View File

@ -662,7 +662,6 @@ bool SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE& aTable )
} }
} }
aTable.Clear();
aTable.Load( fn.GetFullPath() ); aTable.Load( fn.GetFullPath() );
SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager();

View File

@ -334,9 +334,6 @@ public:
virtual ~LIB_TABLE(); virtual ~LIB_TABLE();
/// Delete all rows.
void Clear();
/** /**
* Compares this table against another. * Compares this table against another.
* *
@ -530,6 +527,11 @@ public:
} }
protected: protected:
/*
* Do not make this public. It MUST be called with a lock already in place.
*/
void clear();
/** /**
* Return a #LIB_TABLE_ROW if \a aNickname is found in this table or in any chained * Return a #LIB_TABLE_ROW if \a aNickname is found in this table or in any chained
* fallBack table fragment, else NULL. * fallBack table fragment, else NULL.

View File

@ -1128,16 +1128,12 @@ bool PANEL_FP_LIB_TABLE::TransferDataFromWindow()
if( *global_model() != *m_globalTable ) if( *global_model() != *m_globalTable )
{ {
m_parent->m_GlobalTableChanged = true; m_parent->m_GlobalTableChanged = true;
m_globalTable->Clear();
m_globalTable->TransferRows( global_model()->m_rows ); m_globalTable->TransferRows( global_model()->m_rows );
} }
if( project_model() && *project_model() != *m_projectTable ) if( project_model() && *project_model() != *m_projectTable )
{ {
m_parent->m_ProjectTableChanged = true; m_parent->m_ProjectTableChanged = true;
m_projectTable->Clear();
m_projectTable->TransferRows( project_model()->m_rows ); m_projectTable->TransferRows( project_model()->m_rows );
} }

View File

@ -556,10 +556,9 @@ bool WriteDRCReport( BOARD* aBoard, const wxString& aFileName, EDA_UNITS aUnits,
// Load the global fp-lib-table otherwise we can't check the libs parity // Load the global fp-lib-table otherwise we can't check the libs parity
wxFileName fn_flp = FP_LIB_TABLE::GetGlobalTableFileName(); wxFileName fn_flp = FP_LIB_TABLE::GetGlobalTableFileName();
if( fn_flp.FileExists() ) {
GFootprintTable.Clear(); if( fn_flp.FileExists() )
GFootprintTable.Load( fn_flp.GetFullPath() ); GFootprintTable.Load( fn_flp.GetFullPath() );
}
wxString drcRulesPath = prj->AbsolutePath( fn.GetFullName() ); wxString drcRulesPath = prj->AbsolutePath( fn.GetFullName() );

View File

@ -234,19 +234,6 @@ BOOST_AUTO_TEST_CASE( EmptyWithFallback )
} }
/**
* Check table clearing function
*/
BOOST_AUTO_TEST_CASE( Clear )
{
m_mainTableNoFb.Clear();
// Tables start out empty
BOOST_CHECK_EQUAL( m_mainTableNoFb.GetCount(), 0 );
BOOST_CHECK_EQUAL( true, m_mainTableNoFb.IsEmpty() );
}
/** /**
* Check table equality function * Check table equality function
*/ */