From 2c937f4ae7d749b6b1df3d6bc51f73ab6a867daa Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 18 Dec 2022 21:41:05 +0100 Subject: [PATCH 1/2] Annotate some MT-safe and unsafe wxLog functions Document that wxLog::SetLogLevel() is not MT-safe and that wxLogNull should be used instead of calling it to temporarily change the log level from the other threads. --- interface/wx/log.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/interface/wx/log.h b/interface/wx/log.h index ed9469a6e3..116bb19cff 100644 --- a/interface/wx/log.h +++ b/interface/wx/log.h @@ -384,6 +384,9 @@ public: All messages at levels strictly greater than the value returned by this function are not logged at all. + Note that this function is *not* thread-safe and should only be used + from the main thread. + @see SetLogLevel(), IsLevelEnabled() */ static wxLogLevel GetLogLevel(); @@ -395,6 +398,9 @@ public: @a level is less than or equal to the maximal log level enabled for the given @a component. + Note that this function is *not* thread-safe and should only be used + from the main thread. + @see IsEnabled(), SetLogLevel(), GetLogLevel(), SetComponentLevel() @since 2.9.1 @@ -427,6 +433,10 @@ public: Specifies that log messages with level greater (numerically) than @a logLevel should be ignored and not sent to the active log target. + Note that this function is *not* thread-safe and can only be called + from the main thread. To temporarily disable logging from the other + threads, use wxLogNull, which is safe to use from them. + @see SetComponentLevel() */ static void SetLogLevel(wxLogLevel logLevel); @@ -446,6 +456,9 @@ public: Calling this function with @false argument disables all log messages for the current thread. + This function is thread-safe and can be called by multiple threads + concurrently. + @see wxLogNull, IsEnabled() @return @@ -457,6 +470,9 @@ public: /** Returns true if logging is enabled at all now. + This function is thread-safe and can be called by multiple threads + concurrently. + @see IsLevelEnabled(), EnableLogging() */ static bool IsEnabled(); @@ -937,6 +953,8 @@ public: } @endcode + This class is thread-safe and can be used from both the main and the + backgrounds threads. @library{wxbase} @category{logging} From c7255734dd71a7884e9c8f4d6a02c4e7b558fca6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 18 Dec 2022 21:42:00 +0100 Subject: [PATCH 2/2] Use wxLogNull to temporarily disable logging in wxZipInputStream Using this class is simpler, more efficient and MT-safe, which is important because wxZipInputStream can be used from a background thread (e.g. to decompress a file downloaded from the network etc). --- src/common/zipstrm.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/common/zipstrm.cpp b/src/common/zipstrm.cpp index b6118daa72..28c708576c 100644 --- a/src/common/zipstrm.cpp +++ b/src/common/zipstrm.cpp @@ -146,14 +146,9 @@ static inline wxUint16 CrackUint16(const char *m) static wxFileOffset QuietSeek(wxInputStream& stream, wxFileOffset pos) { #if wxUSE_LOG - wxLogLevel level = wxLog::GetLogLevel(); - wxLog::SetLogLevel(wxLOG_Debug - 1); - wxFileOffset result = stream.SeekI(pos); - wxLog::SetLogLevel(level); - return result; -#else - return stream.SeekI(pos); + wxLogNull noLog; #endif + return stream.SeekI(pos); }