Fix loading of symbols from libs through non-chooser paths

Allow calling PLUGIN::LoadSymbol directly when outside the threaded loader
This commit is contained in:
Jon Evans 2022-08-27 18:47:32 -04:00
parent 49354e52a8
commit 9a8ee2ca50
2 changed files with 13 additions and 1 deletions

View File

@ -345,6 +345,8 @@ void SYMBOL_LIB_TABLE::LoadSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
SYMBOL_LIB_TABLE_ROW* row = FindRow( aNickname, true );
wxCHECK( row && row->plugin, /* void */ );
std::lock_guard<std::mutex> 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<std::mutex> lock( row->GetMutex(), std::try_to_lock );
if( !lock.owns_lock() )
return nullptr;
LIB_SYMBOL* symbol = row->plugin->LoadSymbol( row->GetFullURI( true ), aSymbolName,

View File

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