Remove m_props from symbol library plugins. It's not thread-safe.

Fixes https://gitlab.com/kicad/code/kicad/issues/8035
This commit is contained in:
Jeff Young 2021-03-26 17:30:47 +00:00
parent 3d6c05b210
commit a0a5e93782
5 changed files with 27 additions and 40 deletions

View File

@ -379,7 +379,6 @@ void SCH_SEXPR_PLUGIN::init( SCHEMATIC* aSchematic, const PROPERTIES* aPropertie
{
m_version = 0;
m_rootSheet = nullptr;
m_props = aProperties;
m_schematic = aSchematic;
m_cache = nullptr;
m_out = nullptr;
@ -2070,7 +2069,7 @@ void SCH_SEXPR_PLUGIN_CACHE::DeleteSymbol( const wxString& aSymbolName )
}
void SCH_SEXPR_PLUGIN::cacheLib( const wxString& aLibraryFileName )
void SCH_SEXPR_PLUGIN::cacheLib( const wxString& aLibraryFileName, const PROPERTIES* aProperties )
{
if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
{
@ -2083,7 +2082,7 @@ void SCH_SEXPR_PLUGIN::cacheLib( const wxString& aLibraryFileName )
// must be updated.
PART_LIBS::s_modify_generation++;
if( !isBuffering( m_props ) )
if( !isBuffering( aProperties ) )
m_cache->Load();
}
}
@ -2111,11 +2110,10 @@ void SCH_SEXPR_PLUGIN::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
m_props = aProperties;
bool powerSymbolsOnly = ( aProperties &&
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
cacheLib( aLibraryPath );
cacheLib( aLibraryPath, aProperties );
const LIB_PART_MAP& symbols = m_cache->m_symbols;
@ -2133,11 +2131,10 @@ void SCH_SEXPR_PLUGIN::EnumerateSymbolLib( std::vector<LIB_PART*>& aSymbolList,
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
m_props = aProperties;
bool powerSymbolsOnly = ( aProperties &&
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
cacheLib( aLibraryPath );
cacheLib( aLibraryPath, aProperties );
const LIB_PART_MAP& symbols = m_cache->m_symbols;
@ -2154,9 +2151,7 @@ LIB_PART* SCH_SEXPR_PLUGIN::LoadSymbol( const wxString& aLibraryPath, const wxSt
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
m_props = aProperties;
cacheLib( aLibraryPath );
cacheLib( aLibraryPath, aProperties );
LIB_PART_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
@ -2171,9 +2166,8 @@ void SCH_SEXPR_PLUGIN::SaveSymbol( const wxString& aLibraryPath, const LIB_PART*
const PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
m_props = aProperties;
cacheLib( aLibraryPath );
cacheLib( aLibraryPath, aProperties );
m_cache->AddSymbol( aSymbol );
@ -2186,9 +2180,8 @@ void SCH_SEXPR_PLUGIN::DeleteSymbol( const wxString& aLibraryPath, const wxStrin
const PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
m_props = aProperties;
cacheLib( aLibraryPath );
cacheLib( aLibraryPath, aProperties );
m_cache->DeleteSymbol( aSymbolName );
@ -2209,8 +2202,6 @@ void SCH_SEXPR_PLUGIN::CreateSymbolLib( const wxString& aLibraryPath,
LOCALE_IO toggle;
m_props = aProperties;
delete m_cache;
m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryPath );
m_cache->SetModified();

View File

@ -142,7 +142,7 @@ private:
void saveText( SCH_TEXT* aText, int aNestLevel );
void saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias, int aNestLevel );
void cacheLib( const wxString& aLibraryFileName );
void cacheLib( const wxString& aLibraryFileName, const PROPERTIES* aProperties );
bool isBuffering( const PROPERTIES* aProperties );
protected:
@ -153,7 +153,6 @@ protected:
wxString m_path; ///< Root project path for loading child sheets.
std::stack<wxString> m_currentPath;///< Stack to maintain nested sheet paths
const PROPERTIES* m_props; ///< Passed via Save() or Load(), no ownership, may be nullptr.
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded..
SCHEMATIC* m_schematic; ///< Passed to Load(), the schematic object being loaded
OUTPUTFORMATTER* m_out; ///< The output formatter for saving SCH_SCREEN objects.

View File

@ -581,7 +581,6 @@ void SCH_LEGACY_PLUGIN::init( SCHEMATIC* aSchematic, const PROPERTIES* aProperti
{
m_version = 0;
m_rootSheet = nullptr;
m_props = aProperties;
m_schematic = aSchematic;
m_cache = nullptr;
m_out = nullptr;
@ -4204,7 +4203,7 @@ void SCH_LEGACY_PLUGIN_CACHE::DeleteSymbol( const wxString& aSymbolName )
}
void SCH_LEGACY_PLUGIN::cacheLib( const wxString& aLibraryFileName )
void SCH_LEGACY_PLUGIN::cacheLib( const wxString& aLibraryFileName, const PROPERTIES* aProperties )
{
if( !m_cache || !m_cache->IsFile( aLibraryFileName ) || m_cache->IsFileChanged() )
{
@ -4217,7 +4216,7 @@ void SCH_LEGACY_PLUGIN::cacheLib( const wxString& aLibraryFileName )
// must be updated.
PART_LIBS::s_modify_generation++;
if( !isBuffering( m_props ) )
if( !isBuffering( aProperties ) )
m_cache->Load();
}
}
@ -4256,11 +4255,10 @@ void SCH_LEGACY_PLUGIN::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
m_props = aProperties;
bool powerSymbolsOnly = ( aProperties &&
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
cacheLib( aLibraryPath );
cacheLib( aLibraryPath, aProperties );
const LIB_PART_MAP& symbols = m_cache->m_symbols;
@ -4278,11 +4276,10 @@ void SCH_LEGACY_PLUGIN::EnumerateSymbolLib( std::vector<LIB_PART*>& aSymbolList,
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
m_props = aProperties;
bool powerSymbolsOnly = ( aProperties &&
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
cacheLib( aLibraryPath );
cacheLib( aLibraryPath, aProperties );
const LIB_PART_MAP& symbols = m_cache->m_symbols;
@ -4299,9 +4296,7 @@ LIB_PART* SCH_LEGACY_PLUGIN::LoadSymbol( const wxString& aLibraryPath, const wxS
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
m_props = aProperties;
cacheLib( aLibraryPath );
cacheLib( aLibraryPath, aProperties );
LIB_PART_MAP::const_iterator it = m_cache->m_symbols.find( aSymbolName );
@ -4316,9 +4311,8 @@ void SCH_LEGACY_PLUGIN::SaveSymbol( const wxString& aLibraryPath, const LIB_PART
const PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
m_props = aProperties;
cacheLib( aLibraryPath );
cacheLib( aLibraryPath, aProperties );
m_cache->AddSymbol( aSymbol );
@ -4331,9 +4325,8 @@ void SCH_LEGACY_PLUGIN::DeleteSymbol( const wxString& aLibraryPath, const wxStri
const PROPERTIES* aProperties )
{
LOCALE_IO toggle; // toggles on, then off, the C locale.
m_props = aProperties;
cacheLib( aLibraryPath );
cacheLib( aLibraryPath, aProperties );
m_cache->DeleteSymbol( aSymbolName );
@ -4354,8 +4347,6 @@ void SCH_LEGACY_PLUGIN::CreateSymbolLib( const wxString& aLibraryPath,
LOCALE_IO toggle;
m_props = aProperties;
delete m_cache;
m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryPath );
m_cache->SetModified();

View File

@ -164,7 +164,7 @@ private:
void saveText( SCH_TEXT* aText );
void saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
void cacheLib( const wxString& aLibraryFileName );
void cacheLib( const wxString& aLibraryFileName, const PROPERTIES* aProperties );
bool writeDocFile( const PROPERTIES* aProperties );
bool isBuffering( const PROPERTIES* aProperties );
@ -176,7 +176,6 @@ protected:
wxString m_path; ///< Root project path for loading child sheets.
std::stack<wxString> m_currentPath;///< Stack to maintain nested sheet paths
const PROPERTIES* m_props; ///< Passed via Save() or Load(), no ownership, may be nullptr.
SCH_SHEET* m_rootSheet; ///< The root sheet of the schematic being loaded..
OUTPUTFORMATTER* m_out; ///< The output formatter for saving SCH_SCREEN objects.
SCH_LEGACY_PLUGIN_CACHE* m_cache;

View File

@ -73,9 +73,16 @@ bool SYMBOL_ASYNC_LOADER::Join()
if( m_output && !ret.empty() )
{
for( const LOADED_PAIR& pair : ret )
{
// Don't show libraries that had no power symbols
if( m_onlyPowerSymbols && pair.second.empty() )
continue;
// *Do* show empty libraries in the normal case
m_output->insert( pair );
}
}
}
return true;
}