summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2017-05-04 16:45:22 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2017-11-30 20:19:03 +0000
commitba19363529f4c099c6831c26d3acf98fa0c5f702 (patch)
tree8f09188b3f929988d22c4e5ff1f7066d9435f1f9
parenta0faf9e23666d4aa26a93d6e9ebf420e71d5e6c2 (diff)
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 <thiago.macieira@intel.com>
-rw-r--r--src/corelib/tools/qlocale.cpp23
1 files changed, 17 insertions, 6 deletions
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 <cmath>
+#ifndef QT_NO_SYSTEMLOCALE
+# include "qmutex.h"
+#endif
#ifdef Q_OS_WIN
# include <qt_windows.h>
# include <time.h>
@@ -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