From fc3cad0b54aa357f7cdcaecb5cd4e16f722634f7 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Mon, 7 Feb 2022 15:40:21 -0500 Subject: [PATCH] Hash symbol libraries per library rather than statically per cache type. --- .../sch_plugins/kicad/sch_sexpr_plugin.cpp | 5 --- .../sch_plugins/legacy/sch_legacy_plugin.cpp | 7 +--- eeschema/sch_plugins/sch_lib_plugin_cache.cpp | 9 ++--- eeschema/sch_plugins/sch_lib_plugin_cache.h | 16 ++++----- eeschema/symbol_library.cpp | 34 +++---------------- eeschema/symbol_library.h | 24 +------------ 6 files changed, 18 insertions(+), 77 deletions(-) diff --git a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp index d83fc8aa8d..9a2a0d43d6 100644 --- a/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp +++ b/eeschema/sch_plugins/kicad/sch_sexpr_plugin.cpp @@ -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(); } diff --git a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp index b605959ca6..667c12d503 100644 --- a/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp +++ b/eeschema/sch_plugins/legacy/sch_legacy_plugin.cpp @@ -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; diff --git a/eeschema/sch_plugins/sch_lib_plugin_cache.cpp b/eeschema/sch_plugins/sch_lib_plugin_cache.cpp index 225f2eb79c..812de32afd 100644 --- a/eeschema/sch_plugins/sch_lib_plugin_cache.cpp +++ b/eeschema/sch_plugins/sch_lib_plugin_cache.cpp @@ -25,11 +25,8 @@ #include -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(); } diff --git a/eeschema/sch_plugins/sch_lib_plugin_cache.h b/eeschema/sch_plugins/sch_lib_plugin_cache.h index 4d7b419b2a..020eb659f5 100644 --- a/eeschema/sch_plugins/sch_lib_plugin_cache.h +++ b/eeschema/sch_plugins/sch_lib_plugin_cache.h @@ -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 mut( SCH_LIB_PLUGIN_CACHE::m_modHashMutex ); - SCH_LIB_PLUGIN_CACHE::m_modHash++; + std::lock_guard mut( m_modHashMutex ); + m_modHash++; } - static int GetModifyHash() + int GetModifyHash() { - std::lock_guard mut( SCH_LIB_PLUGIN_CACHE::m_modHashMutex ); - return SCH_LIB_PLUGIN_CACHE::m_modHash; + std::lock_guard 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. diff --git a/eeschema/symbol_library.cpp b/eeschema/symbol_library.cpp index b30763a995..d2d9675c03 100644 --- a/eeschema/symbol_library.cpp +++ b/eeschema/symbol_library.cpp @@ -3,7 +3,7 @@ * * Copyright (C) 2004-2016 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2008 Wayne Stambaugh - * 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 @@ -45,10 +45,7 @@ #include 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() ), + SCH_IO_MGR::SCH_FILE_T aPluginType ) : m_pluginType( aPluginType ) { type = aType; @@ -75,8 +72,9 @@ SYMBOL_LIB::~SYMBOL_LIB() void SYMBOL_LIB::Save( bool aSaveDocFile ) { - wxCHECK_RET( m_plugin != nullptr, wxString::Format( "no plugin defined for library `%s`.", - fileName.GetFullPath() ) ); + 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& 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 ) { diff --git a/eeschema/symbol_library.h b/eeschema/symbol_library.h index 12ad51008a..0fdf5c0fc2 100644 --- a/eeschema/symbol_library.h +++ b/eeschema/symbol_library.h @@ -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 mut( SYMBOL_LIBS::s_generationMutex ); - ++SYMBOL_LIBS::s_modify_generation; - } - - static int GetModifyGeneration() - { - std::lock_guard 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; };