diff --git a/common/fp_lib_table.cpp b/common/fp_lib_table.cpp index f8b8d740db..98aadf2bb1 100644 --- a/common/fp_lib_table.cpp +++ b/common/fp_lib_table.cpp @@ -205,15 +205,15 @@ void FP_LIB_TABLE::Parse( LIB_TABLE_LEXER* in ) if( !sawUri ) in->Expecting( T_uri ); - // all nickNames within this table fragment must be unique, so we do not - // use doReplace in InsertRow(). (However a fallBack table can have a - // conflicting nickName and ours will supercede that one since in - // FindLib() we search this table before any fall back.) - wxString nickname = row->GetNickName(); // store it to be able to used it - // after row deletion if an error occurs + // All nickNames within this table fragment must be unique, so we do not use doReplace + // in doInsertRow(). (However a fallBack table can have a conflicting nickName and ours + // will supercede that one since in FindLib() we search this table before any fall back.) + wxString nickname = row->GetNickName(); // store it to be able to used it + // after row deletion if an error occurs + bool doReplace = false; LIB_TABLE_ROW* tmp = row.release(); - if( !InsertRow( tmp ) ) + if( !doInsertRow( tmp, doReplace ) ) { delete tmp; // The table did not take ownership of the row. diff --git a/common/lib_table_base.cpp b/common/lib_table_base.cpp index 126f91e774..938224675a 100644 --- a/common/lib_table_base.cpp +++ b/common/lib_table_base.cpp @@ -309,6 +309,15 @@ bool LIB_TABLE::InsertRow( LIB_TABLE_ROW* aRow, bool doReplace ) { std::lock_guard lock( m_mutex ); + doInsertRow( aRow, doReplace ); + reindex(); + + return true; +} + + +bool LIB_TABLE::doInsertRow( LIB_TABLE_ROW* aRow, bool doReplace ) +{ auto it = m_rowsMap.find( aRow->GetNickName() ); if( it != m_rowsMap.end() ) @@ -452,7 +461,7 @@ bool LIB_TABLE::migrate() void LIB_TABLE::Load( const wxString& aFileName ) { - std::shared_lock lock( m_mutex ); + std::lock_guard lock( m_mutex ); clear(); // It's OK if footprint library tables are missing. diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index 1e7a07e57c..803f35abe9 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -272,15 +272,15 @@ void SYMBOL_LIB_TABLE::Parse( LIB_TABLE_LEXER* in ) if( !sawUri ) in->Expecting( T_uri ); - // all nickNames within this table fragment must be unique, so we do not - // use doReplace in InsertRow(). (However a fallBack table can have a - // conflicting nickName and ours will supercede that one since in - // FindLib() we search this table before any fall back.) - wxString nickname = row->GetNickName(); // store it to be able to used it - // after row deletion if an error occurs + // All nickNames within this table fragment must be unique, so we do not use doReplace + // in doInsertRow(). (However a fallBack table can have a conflicting nickName and ours + // will supercede that one since in FindLib() we search this table before any fall back.) + wxString nickname = row->GetNickName(); // store it to be able to used it + // after row deletion if an error occurs + bool doReplace = false; LIB_TABLE_ROW* tmp = row.release(); - if( !InsertRow( tmp ) ) + if( !doInsertRow( tmp, doReplace ) ) { delete tmp; // The table did not take ownership of the row. @@ -606,7 +606,7 @@ public: m_lib_table.InsertRow( new SYMBOL_LIB_TABLE_ROW( nickname, libPath, wxT( "KiCad" ), wxEmptyString, - _( "Added by Plugin and Content Manager" ) ) ); + _( "Added by Plugin and Content Manager" ) ), false ); } } diff --git a/include/lib_table_base.h b/include/lib_table_base.h index 508f1afd1d..7a24c9cec1 100644 --- a/include/lib_table_base.h +++ b/include/lib_table_base.h @@ -542,6 +542,11 @@ protected: */ LIB_TABLE_ROW* findRow( const wxString& aNickname, bool aCheckIfEnabled = false ) const; + /** + * Performs the mechanics of inserting a row, but without locking or reindexing. + */ + bool doInsertRow( LIB_TABLE_ROW* aRow, bool doReplace = false ); + /** * Updates the env vars from older version of KiCad, provided they do not currently * resolve to anything @@ -550,6 +555,9 @@ protected: */ bool migrate(); + /* + * Do not make this public. It MUST be called with a lock already in place. + */ void reindex(); protected: