mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-07 18:35:32 +00:00
Fix several data races triggered by parallel library loading
This commit is contained in:
parent
7080d99464
commit
42b9a9604b
common
include/settings
@ -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 );
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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" ) )
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user