diff --git a/common/common.cpp b/common/common.cpp index 388a8032f8..976e419d18 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -64,14 +64,12 @@ EDA_COLOR_T g_GhostColor; * is thrown, or not. */ -int LOCALE_IO::m_c_count = 0; +std::atomic LOCALE_IO::m_c_count(0); LOCALE_IO::LOCALE_IO() { - wxASSERT_MSG( m_c_count >= 0, wxT( "LOCALE_IO::m_c_count mismanaged." ) ); - // use thread safe, atomic operation - if( __sync_fetch_and_add( &m_c_count, 1 ) == 0 ) + if( m_c_count++ == 0 ) { // Store the user locale name, to restore this locale later, in dtor m_user_locale = setlocale( LC_ALL, 0 ); @@ -83,13 +81,11 @@ LOCALE_IO::LOCALE_IO() LOCALE_IO::~LOCALE_IO() { // use thread safe, atomic operation - if( __sync_sub_and_fetch( &m_c_count, 1 ) == 0 ) + if( --m_c_count == 0 ) { // revert to the user locale setlocale( LC_ALL, m_user_locale.c_str() ); } - - wxASSERT_MSG( m_c_count >= 0, wxT( "LOCALE_IO::m_c_count mismanaged." ) ); } diff --git a/include/common.h b/include/common.h index 97bf56d781..70e73794e6 100644 --- a/include/common.h +++ b/include/common.h @@ -42,6 +42,8 @@ #include #include +#include + class wxAboutDialogInfo; class SEARCH_STACK; @@ -199,7 +201,7 @@ private: void setUserLocale( const char* aUserLocale ); // allow for nesting of LOCALE_IO instantiations - static int m_c_count; + static std::atomic m_c_count; // The locale in use before switching to the "C" locale // (the locale can be set by user, and is not always the system locale)