diff --git a/eeschema/symbol_lib_table.cpp b/eeschema/symbol_lib_table.cpp index ef0d84f048..0a09426903 100644 --- a/eeschema/symbol_lib_table.cpp +++ b/eeschema/symbol_lib_table.cpp @@ -345,6 +345,8 @@ void SYMBOL_LIB_TABLE::LoadSymbolLib( std::vector& aSymbolList, SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true ); wxCHECK( row && row->plugin, /* void */ ); + std::lock_guard lock( row->GetMutex() ); + wxString options = row->GetOptions(); if( aPowerSymbolsOnly ) @@ -375,7 +377,13 @@ LIB_SYMBOL* SYMBOL_LIB_TABLE::LoadSymbol( const wxString& aNickname, const wxStr { SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true ); - if( !row || !row->plugin || !row->GetIsLoaded() ) + if( !row || !row->plugin ) + return nullptr; + + // If another thread is loading this library at the moment; continue + std::unique_lock lock( row->GetMutex(), std::try_to_lock ); + + if( !lock.owns_lock() ) return nullptr; LIB_SYMBOL* symbol = row->plugin->LoadSymbol( row->GetFullURI( true ), aSymbolName, diff --git a/include/lib_table_base.h b/include/lib_table_base.h index 3cb96feca8..e8a9ef516c 100644 --- a/include/lib_table_base.h +++ b/include/lib_table_base.h @@ -180,6 +180,8 @@ public: void SetParent( LIB_TABLE* aParent ) { m_parent = aParent; } + std::mutex& GetMutex() { return m_loadMutex; } + /** * Return the constant #PROPERTIES for this library (#LIB_TABLE_ROW). These are * the "options" in a table. @@ -244,6 +246,8 @@ private: LIB_TABLE* m_parent; ///< Pointer to the table this row lives in (maybe null) std::unique_ptr< PROPERTIES > properties; + + std::mutex m_loadMutex; };