diff --git a/common/font/font.cpp b/common/font/font.cpp index d8554c1fe4..a8ecd6cae1 100644 --- a/common/font/font.cpp +++ b/common/font/font.cpp @@ -127,6 +127,7 @@ private: static MARKUP_CACHE s_markupCache( 1024 ); static std::mutex s_markupCacheMutex; +static std::mutex s_defaultFontMutex;; FONT::FONT() @@ -136,6 +137,8 @@ FONT::FONT() FONT* FONT::getDefaultFont() { + std::lock_guard lock( s_defaultFontMutex ); + if( !s_defaultFont ) s_defaultFont = STROKE_FONT::LoadFont( wxEmptyString ); diff --git a/common/font/fontconfig.cpp b/common/font/fontconfig.cpp index 193582fddb..581a2738fb 100644 --- a/common/font/fontconfig.cpp +++ b/common/font/fontconfig.cpp @@ -19,7 +19,7 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ - +#include <mutex> #include <font/fontconfig.h> #include <wx/log.h> #include <trace_helpers.h> @@ -40,6 +40,7 @@ static FONTCONFIG* g_config = nullptr; static bool g_fcInitSuccess = false; REPORTER* FONTCONFIG::s_reporter = nullptr; +static std::mutex g_fontConfigMutex; /** * A simple wrapper to avoid exporting fontconfig in the header @@ -63,6 +64,7 @@ FONTCONFIG::FONTCONFIG() void fontconfig::FONTCONFIG::SetReporter( REPORTER* aReporter ) { + std::lock_guard lock( g_fontConfigMutex ); s_reporter = aReporter; } diff --git a/common/io/altium/altium_binary_parser.cpp b/common/io/altium/altium_binary_parser.cpp index fb40e982d7..af2940f489 100644 --- a/common/io/altium/altium_binary_parser.cpp +++ b/common/io/altium/altium_binary_parser.cpp @@ -338,6 +338,8 @@ ALTIUM_BINARY_PARSER::ALTIUM_BINARY_PARSER( std::unique_ptr<char[]>& aContent, s std::map<wxString, wxString> ALTIUM_BINARY_PARSER::ReadProperties( std::function<std::map<wxString, wxString>( const std::string& )> handleBinaryData ) { + // TSAN reports calling this wx macro is not thread-safe + static wxCSConv convISO8859_1 = wxConvISO8859_1; std::map<wxString, wxString> kv; @@ -412,7 +414,7 @@ std::map<wxString, wxString> ALTIUM_BINARY_PARSER::ReadProperties( // convert the strings to wxStrings, since we use them everywhere // value can have non-ASCII characters, so we convert them from LATIN1/ISO8859-1 - wxString key( keyS.c_str(), wxConvISO8859_1 ); + wxString key( keyS.c_str(), convISO8859_1 ); // Altium stores keys either in Upper, or in CamelCase. Lets unify it. wxString canonicalKey = key.Trim( false ).Trim( true ).MakeUpper(); @@ -423,7 +425,7 @@ std::map<wxString, wxString> ALTIUM_BINARY_PARSER::ReadProperties( if( canonicalKey.StartsWith( "%UTF8%" ) ) value = wxString( valueS.c_str(), wxConvUTF8 ); else - value = wxString( valueS.c_str(), wxConvISO8859_1 ); + value = wxString( valueS.c_str(), convISO8859_1 ); if( canonicalKey != wxS( "PATTERN" ) && canonicalKey != wxS( "SOURCEFOOTPRINTLIBRARY" ) ) { diff --git a/common/reporter.cpp b/common/reporter.cpp index c46e8a1289..4b973c407d 100644 --- a/common/reporter.cpp +++ b/common/reporter.cpp @@ -25,6 +25,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include <mutex> #include <macros.h> #include <reporter.h> #include <string_utils.h> @@ -42,6 +43,8 @@ */ static const wxChar traceReporter[] = wxT( "KICAD_REPORTER" ); +static std::mutex g_logReporterMutex; + REPORTER& REPORTER::Report( const char* aText, SEVERITY aSeverity ) { @@ -199,6 +202,7 @@ REPORTER& WXLOG_REPORTER::Report( const wxString& aMsg, SEVERITY aSeverity ) REPORTER& WXLOG_REPORTER::GetInstance() { static REPORTER* s_wxLogReporter = nullptr; + std::lock_guard lock( g_logReporterMutex ); if( !s_wxLogReporter ) s_wxLogReporter = new WXLOG_REPORTER(); @@ -222,4 +226,4 @@ bool STATUSBAR_REPORTER::HasMessage() const return !m_statusBar->GetStatusText( m_position ).IsEmpty(); return false; -} \ No newline at end of file +} diff --git a/include/settings/settings_manager.h b/include/settings/settings_manager.h index d02a21543d..7eb03daec3 100644 --- a/include/settings/settings_manager.h +++ b/include/settings/settings_manager.h @@ -103,6 +103,8 @@ public: template<typename T> T* GetAppSettings( const wxString& aFilename ) { + std::lock_guard lock( m_app_settings_mutex ); + T* ret = nullptr; size_t typeHash = typeid( T ).hash_code(); @@ -456,6 +458,7 @@ private: /// Cache for app settings std::unordered_map<size_t, JSON_SETTINGS*> m_app_settings_cache; + std::mutex m_app_settings_mutex; // Convenience shortcut COMMON_SETTINGS* m_common_settings;