From ba19363529f4c099c6831c26d3acf98fa0c5f702 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 4 May 2017 16:45:22 +0200 Subject: Mutex-lock QLocale's update of its globalLocaleData For want of this, nothing that used QLocale::system(), inter alia, could be thread-safe or re-entrant. Task-number: QTBUG-49473 Change-Id: I3e017aa7d59c4c39828bb5cdc7ff0780ea66bafe Reviewed-by: Thiago Macieira --- src/corelib/tools/qlocale.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 179784c7ba..06beabbee3 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -64,6 +64,9 @@ #include "qstringbuilder.h" #include "private/qnumeric_p.h" #include +#ifndef QT_NO_SYSTEMLOCALE +# include "qmutex.h" +#endif #ifdef Q_OS_WIN # include # include @@ -593,8 +596,6 @@ static QLocalePrivate *c_private() } #ifndef QT_NO_SYSTEMLOCALE - - /****************************************************************************** ** Default system locale behavior */ @@ -683,14 +684,24 @@ void QLocalePrivate::updateSystemPrivate() if (!res.isNull()) system_data->m_plus = res.toString().at(0).unicode(); } -#endif +#endif // !QT_NO_SYSTEMLOCALE static const QLocaleData *systemData() { #ifndef QT_NO_SYSTEMLOCALE - // copy over the information from the fallback locale and modify - if (!system_data || system_data->m_language_id == 0) - QLocalePrivate::updateSystemPrivate(); + /* + Copy over the information from the fallback locale and modify. + + This modifies (cross-thread) global state, so take care to only call it in + one thread. + */ + { + static QBasicMutex systemDataMutex; + systemDataMutex.lock(); + if (!system_data || system_data->m_language_id == 0) + QLocalePrivate::updateSystemPrivate(); + systemDataMutex.unlock(); + } return system_data; #else -- cgit v1.2.3