Use std::atomic for portable locale init counting
This commit is contained in:
parent
e795dafc4b
commit
f7fdf43ea8
|
@ -64,14 +64,12 @@ EDA_COLOR_T g_GhostColor;
|
|||
* is thrown, or not.
|
||||
*/
|
||||
|
||||
int LOCALE_IO::m_c_count = 0;
|
||||
std::atomic<unsigned int> 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." ) );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
#include <richio.h>
|
||||
#include <colors.h>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
|
||||
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<unsigned int> 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)
|
||||
|
|
Loading…
Reference in New Issue