From 0f099ac65e908c56ff96bccd40639329a3f1de3c Mon Sep 17 00:00:00 2001 From: Jeff Young <jeff@rokeby.ie> Date: Sun, 21 Jul 2024 17:37:45 +0100 Subject: [PATCH] Use lock when clearing and loading libTables. Also make sure it's re-indexed after loading. --- common/fp_lib_table.cpp | 1 - common/lib_table_base.cpp | 8 +++++++- eeschema/dialogs/panel_sym_lib_table.cpp | 4 ---- eeschema/symbol_lib_table.cpp | 1 - include/lib_table_base.h | 8 +++++--- pcbnew/dialogs/panel_fp_lib_table.cpp | 4 ---- .../python/scripting/pcbnew_scripting_helpers.cpp | 5 ++--- qa/tests/common/test_lib_table.cpp | 13 ------------- 8 files changed, 14 insertions(+), 30 deletions(-) diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index 1c63bead2c..f8b8d740db 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -607,7 +607,6 @@ bool FP_LIB_TABLE::LoadGlobalTable( FP_LIB_TABLE& aTable ) } } - aTable.Clear(); aTable.Load( fn.GetFullPath() ); SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); diff --git a/common/lib_table_base.cpp b/common/lib_table_base.cpp index a4af4a6c10..126f91e774 100644 --- a/common/lib_table_base.cpp +++ b/common/lib_table_base.cpp @@ -128,7 +128,7 @@ LIB_TABLE::~LIB_TABLE() } -void LIB_TABLE::Clear() +void LIB_TABLE::clear() { m_rows.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 ); + clear(); m_rows.transfer( m_rows.end(), aRowsList.begin(), aRowsList.end(), aRowsList ); reindex(); @@ -451,6 +452,9 @@ bool LIB_TABLE::migrate() 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. if( wxFileName::IsFileReadable( aFileName ) ) { @@ -461,6 +465,8 @@ void LIB_TABLE::Load( const wxString& aFileName ) if( m_version != 7 && migrate() && wxFileName::IsFileWritable( aFileName ) ) Save( aFileName ); + + reindex(); } } diff --git a/eeschema/dialogs/panel_sym_lib_table.cpp b/eeschema/dialogs/panel_sym_lib_table.cpp index 54e89bd367..741540d9af 100644 --- a/eeschema/dialogs/panel_sym_lib_table.cpp +++ b/eeschema/dialogs/panel_sym_lib_table.cpp @@ -1014,16 +1014,12 @@ bool PANEL_SYM_LIB_TABLE::TransferDataFromWindow() if( *global_model() != *m_globalTable ) { m_parent->m_GlobalTableChanged = true; - - m_globalTable->Clear(); m_globalTable->TransferRows( global_model()->m_rows ); } if( project_model() && *project_model() != *m_projectTable ) { m_parent->m_ProjectTableChanged = true; - - m_projectTable->Clear(); m_projectTable->TransferRows( project_model()->m_rows ); } diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index 35c56bcef7..1e7a07e57c 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -662,7 +662,6 @@ bool SYMBOL_LIB_TABLE::LoadGlobalTable( SYMBOL_LIB_TABLE& aTable ) } } - aTable.Clear(); aTable.Load( fn.GetFullPath() ); SETTINGS_MANAGER& mgr = Pgm().GetSettingsManager(); diff --git a/include/lib_table_base.h b/include/lib_table_base.h index e30b9126d5..508f1afd1d 100644 --- a/include/lib_table_base.h +++ b/include/lib_table_base.h @@ -334,9 +334,6 @@ public: virtual ~LIB_TABLE(); - /// Delete all rows. - void Clear(); - /** * Compares this table against another. * @@ -530,6 +527,11 @@ public: } 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 * fallBack table fragment, else NULL. diff --git a/pcbnew/dialogs/panel_fp_lib_table.cpp b/pcbnew/dialogs/panel_fp_lib_table.cpp index e181a9e0b4..2db174b60c 100644 --- a/pcbnew/dialogs/panel_fp_lib_table.cpp +++ b/pcbnew/dialogs/panel_fp_lib_table.cpp @@ -1128,16 +1128,12 @@ bool PANEL_FP_LIB_TABLE::TransferDataFromWindow() if( *global_model() != *m_globalTable ) { m_parent->m_GlobalTableChanged = true; - - m_globalTable->Clear(); m_globalTable->TransferRows( global_model()->m_rows ); } if( project_model() && *project_model() != *m_projectTable ) { m_parent->m_ProjectTableChanged = true; - - m_projectTable->Clear(); m_projectTable->TransferRows( project_model()->m_rows ); } diff --git a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp index 2485706660..ed602cde75 100644 --- a/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp +++ b/pcbnew/python/scripting/pcbnew_scripting_helpers.cpp @@ -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 wxFileName fn_flp = FP_LIB_TABLE::GetGlobalTableFileName(); - if( fn_flp.FileExists() ) { - GFootprintTable.Clear(); + + if( fn_flp.FileExists() ) GFootprintTable.Load( fn_flp.GetFullPath() ); - } wxString drcRulesPath = prj->AbsolutePath( fn.GetFullName() ); diff --git a/qa/tests/common/test_lib_table.cpp b/qa/tests/common/test_lib_table.cpp index 3324bad5cf..672c497004 100644 --- a/qa/tests/common/test_lib_table.cpp +++ b/qa/tests/common/test_lib_table.cpp @@ -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 */