Hash symbol libraries per library rather than statically per cache type.
This commit is contained in:
parent
d0d472f39d
commit
fc3cad0b54
|
@ -2230,11 +2230,6 @@ void SCH_SEXPR_PLUGIN::cacheLib( const wxString& aLibraryFileName, const PROPERT
|
|||
delete m_cache;
|
||||
m_cache = new SCH_SEXPR_PLUGIN_CACHE( aLibraryFileName );
|
||||
|
||||
// Because m_cache is rebuilt, increment SYMBOL_LIBS::s_modify_generation
|
||||
// to modify the hash value that indicate symbol to symbol links
|
||||
// must be updated.
|
||||
SYMBOL_LIBS::IncrementModifyGeneration();
|
||||
|
||||
if( !isBuffering( aProperties ) )
|
||||
m_cache->Load();
|
||||
}
|
||||
|
|
|
@ -1963,11 +1963,6 @@ void SCH_LEGACY_PLUGIN::cacheLib( const wxString& aLibraryFileName, const PROPER
|
|||
delete m_cache;
|
||||
m_cache = new SCH_LEGACY_PLUGIN_CACHE( aLibraryFileName );
|
||||
|
||||
// Because m_cache is rebuilt, increment SYMBOL_LIBS::s_modify_generation
|
||||
// to modify the hash value that indicate symbol to symbol links
|
||||
// must be updated.
|
||||
SYMBOL_LIBS::IncrementModifyGeneration();
|
||||
|
||||
if( !isBuffering( aProperties ) )
|
||||
m_cache->Load();
|
||||
}
|
||||
|
@ -1994,7 +1989,7 @@ bool SCH_LEGACY_PLUGIN::isBuffering( const PROPERTIES* aProperties )
|
|||
int SCH_LEGACY_PLUGIN::GetModifyHash() const
|
||||
{
|
||||
if( m_cache )
|
||||
return SCH_LEGACY_PLUGIN_CACHE::GetModifyHash();
|
||||
return m_cache->GetModifyHash();
|
||||
|
||||
// If the cache hasn't been loaded, it hasn't been modified.
|
||||
return 0;
|
||||
|
|
|
@ -25,11 +25,8 @@
|
|||
#include <wx_filename.h>
|
||||
|
||||
|
||||
int SCH_LIB_PLUGIN_CACHE::m_modHash = 1; // starts at 1 and goes up
|
||||
std::mutex SCH_LIB_PLUGIN_CACHE::m_modHashMutex;
|
||||
|
||||
|
||||
SCH_LIB_PLUGIN_CACHE::SCH_LIB_PLUGIN_CACHE( const wxString& aFullPathAndFileName ) :
|
||||
m_modHash( 1 ),
|
||||
m_fileName( aFullPathAndFileName ),
|
||||
m_libFileName( aFullPathAndFileName ),
|
||||
m_isWritable( true ),
|
||||
|
@ -154,7 +151,7 @@ LIB_SYMBOL* SCH_LIB_PLUGIN_CACHE::removeSymbol( LIB_SYMBOL* aSymbol )
|
|||
m_symbols.erase( it );
|
||||
delete aSymbol;
|
||||
m_isModified = true;
|
||||
SCH_LIB_PLUGIN_CACHE::IncrementModifyHash();
|
||||
IncrementModifyHash();
|
||||
return firstChild;
|
||||
}
|
||||
|
||||
|
@ -172,5 +169,5 @@ void SCH_LIB_PLUGIN_CACHE::AddSymbol( const LIB_SYMBOL* aSymbol )
|
|||
|
||||
m_symbols[ name ] = const_cast< LIB_SYMBOL* >( aSymbol );
|
||||
m_isModified = true;
|
||||
SCH_LIB_PLUGIN_CACHE::IncrementModifyHash();
|
||||
IncrementModifyHash();
|
||||
}
|
||||
|
|
|
@ -43,16 +43,16 @@ public:
|
|||
SCH_LIB_PLUGIN_CACHE( const wxString& aLibraryPath );
|
||||
virtual ~SCH_LIB_PLUGIN_CACHE();
|
||||
|
||||
static void IncrementModifyHash()
|
||||
void IncrementModifyHash()
|
||||
{
|
||||
std::lock_guard<std::mutex> mut( SCH_LIB_PLUGIN_CACHE::m_modHashMutex );
|
||||
SCH_LIB_PLUGIN_CACHE::m_modHash++;
|
||||
std::lock_guard<std::mutex> mut( m_modHashMutex );
|
||||
m_modHash++;
|
||||
}
|
||||
|
||||
static int GetModifyHash()
|
||||
int GetModifyHash()
|
||||
{
|
||||
std::lock_guard<std::mutex> mut( SCH_LIB_PLUGIN_CACHE::m_modHashMutex );
|
||||
return SCH_LIB_PLUGIN_CACHE::m_modHash;
|
||||
std::lock_guard<std::mutex> mut( m_modHashMutex );
|
||||
return m_modHash;
|
||||
}
|
||||
|
||||
// Most all functions in this class throw IO_ERROR exceptions. There are no
|
||||
|
@ -88,8 +88,8 @@ public:
|
|||
protected:
|
||||
LIB_SYMBOL* removeSymbol( LIB_SYMBOL* aAlias );
|
||||
|
||||
static int m_modHash; // Keep track of the modification status of the library.
|
||||
static std::mutex m_modHashMutex;
|
||||
int m_modHash; // Keep track of the modification status of the library.
|
||||
std::mutex m_modHashMutex;
|
||||
|
||||
wxString m_fileName; // Absolute path and file name.
|
||||
wxFileName m_libFileName; // Absolute path and file name is required here.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2004-2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
||||
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
|
||||
* Copyright (C) 2004-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2004-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
|
@ -46,9 +46,6 @@
|
|||
|
||||
SYMBOL_LIB::SYMBOL_LIB( SCH_LIB_TYPE aType, const wxString& aFileName,
|
||||
SCH_IO_MGR::SCH_FILE_T aPluginType ) :
|
||||
// start @ != 0 so each additional library added
|
||||
// is immediately detectable, zero would not be.
|
||||
m_mod_hash( SYMBOL_LIBS::GetModifyGeneration() ),
|
||||
m_pluginType( aPluginType )
|
||||
{
|
||||
type = aType;
|
||||
|
@ -75,7 +72,8 @@ SYMBOL_LIB::~SYMBOL_LIB()
|
|||
|
||||
void SYMBOL_LIB::Save( bool aSaveDocFile )
|
||||
{
|
||||
wxCHECK_RET( m_plugin != nullptr, wxString::Format( "no plugin defined for library `%s`.",
|
||||
wxCHECK_RET( m_plugin != nullptr,
|
||||
wxString::Format( wxT( "no plugin defined for library `%s`." ),
|
||||
fileName.GetFullPath() ) );
|
||||
|
||||
PROPERTIES props;
|
||||
|
@ -409,28 +407,6 @@ void SYMBOL_LIBS::FindLibraryNearEntries( std::vector<LIB_SYMBOL*>& aCandidates,
|
|||
}
|
||||
|
||||
|
||||
int SYMBOL_LIBS::s_modify_generation = 1; // starts at 1 and goes up
|
||||
std::mutex SYMBOL_LIBS::s_generationMutex;
|
||||
|
||||
|
||||
int SYMBOL_LIBS::GetModifyHash()
|
||||
{
|
||||
int hash = 0;
|
||||
|
||||
for( SYMBOL_LIBS::const_iterator it = begin(); it != end(); ++it )
|
||||
{
|
||||
hash += it->GetModHash();
|
||||
}
|
||||
|
||||
// Rebuilding the cache (m_cache) does not change the GetModHash() value,
|
||||
// but changes SYMBOL_LIBS::s_modify_generation.
|
||||
// Take this change in account:
|
||||
hash += SYMBOL_LIBS::GetModifyGeneration();
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
void SYMBOL_LIBS::LibNamesAndPaths( PROJECT* aProject, bool doSave,
|
||||
wxString* aPaths, wxArrayString* aNames )
|
||||
{
|
||||
|
|
|
@ -64,26 +64,7 @@ class SYMBOL_LIBS : public SYMBOL_LIBS_BASE, public PROJECT::_ELEM
|
|||
public:
|
||||
KICAD_T Type() override { return SYMBOL_LIBS_T; }
|
||||
|
||||
SYMBOL_LIBS()
|
||||
{
|
||||
IncrementModifyGeneration();
|
||||
}
|
||||
|
||||
static void IncrementModifyGeneration()
|
||||
{
|
||||
std::lock_guard<std::mutex> mut( SYMBOL_LIBS::s_generationMutex );
|
||||
++SYMBOL_LIBS::s_modify_generation;
|
||||
}
|
||||
|
||||
static int GetModifyGeneration()
|
||||
{
|
||||
std::lock_guard<std::mutex> mut( SYMBOL_LIBS::s_generationMutex );
|
||||
return SYMBOL_LIBS::s_modify_generation;
|
||||
}
|
||||
|
||||
/// Return the modification hash for all libraries. The value returned
|
||||
/// changes on every library modification.
|
||||
int GetModifyHash();
|
||||
SYMBOL_LIBS() {}
|
||||
|
||||
/**
|
||||
* Allocate and adds a symbol library to the library list.
|
||||
|
@ -175,9 +156,6 @@ public:
|
|||
const wxString& aLibraryName = wxEmptyString );
|
||||
|
||||
int GetLibraryCount() { return size(); }
|
||||
|
||||
static int s_modify_generation; ///< helper for GetModifyHash()
|
||||
static std::mutex s_generationMutex;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue