7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 00:21:25 +00:00

Don't deadlock when adding rows.

This commit is contained in:
Jeff Young 2024-07-23 17:49:34 +01:00
parent 51792fc5ea
commit 431087fc7c
4 changed files with 33 additions and 16 deletions

View File

@ -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.

View File

@ -309,6 +309,15 @@ bool LIB_TABLE::InsertRow( LIB_TABLE_ROW* aRow, bool doReplace )
{
std::lock_guard<std::shared_mutex> 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<std::shared_mutex> lock( m_mutex );
std::lock_guard<std::shared_mutex> lock( m_mutex );
clear();
// It's OK if footprint library tables are missing.

View File

@ -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 );
}
}

View File

@ -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: