diff options
Diffstat (limited to 'src/corelib/time/qtimezoneprivate_tz.cpp')
-rw-r--r-- | src/corelib/time/qtimezoneprivate_tz.cpp | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp index f70b6eab3d..55914cc7da 100644 --- a/src/corelib/time/qtimezoneprivate_tz.cpp +++ b/src/corelib/time/qtimezoneprivate_tz.cpp @@ -1,14 +1,13 @@ /**************************************************************************** ** -** Copyright (C) 2021 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2019 Crimson AS <info@crimson.no> ** Copyright (C) 2013 John Layt <jlayt@kde.org> ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:COMM$ -** +** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the @@ -17,31 +16,33 @@ ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** -** $QT_END_LICENSE$ -** -** -** -** -** -** -** -** -** -** -** -** -** -** -** -** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** +** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qtimezone.h" #include "qtimezoneprivate_p.h" #include "private/qlocale_tools_p.h" +#include "private/qlocking_p.h" #include <QtCore/QDataStream> #include <QtCore/QDateTime> @@ -62,6 +63,10 @@ QT_BEGIN_NAMESPACE +#if QT_CONFIG(icu) +static QBasicMutex s_icu_mutex; +#endif + /* Private @@ -654,14 +659,8 @@ static QVector<QTimeZonePrivate::Data> calculatePosixTransitions(const QByteArra // Create the system default time zone QTzTimeZonePrivate::QTzTimeZonePrivate() + : QTzTimeZonePrivate(staticSystemTimeZoneId()) { - init(systemTimeZoneId()); -} - -// Create a named time zone -QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId) -{ - init(ianaId); } QTzTimeZonePrivate::~QTzTimeZonePrivate() @@ -670,6 +669,9 @@ QTzTimeZonePrivate::~QTzTimeZonePrivate() QTzTimeZonePrivate *QTzTimeZonePrivate::clone() const { +#if QT_CONFIG(icu) + const auto lock = qt_scoped_lock(s_icu_mutex); +#endif return new QTzTimeZonePrivate(*this); } @@ -872,7 +874,8 @@ QTzTimeZoneCacheEntry QTzTimeZoneCache::fetchEntry(const QByteArray &ianaId) return ret; } -void QTzTimeZonePrivate::init(const QByteArray &ianaId) +// Create a named time zone +QTzTimeZonePrivate::QTzTimeZonePrivate(const QByteArray &ianaId) { static QTzTimeZoneCache tzCache; auto entry = tzCache.fetchEntry(ianaId); @@ -913,12 +916,14 @@ QString QTzTimeZonePrivate::displayName(qint64 atMSecsSinceEpoch, const QLocale &locale) const { #if QT_CONFIG(icu) + auto lock = qt_unique_lock(s_icu_mutex); if (!m_icu) m_icu = new QIcuTimeZonePrivate(m_id); // TODO small risk may not match if tran times differ due to outdated files // TODO Some valid TZ names are not valid ICU names, use translation table? if (m_icu->isValid()) return m_icu->displayName(atMSecsSinceEpoch, nameType, locale); + lock.unlock(); #else Q_UNUSED(nameType) Q_UNUSED(locale) @@ -932,12 +937,14 @@ QString QTzTimeZonePrivate::displayName(QTimeZone::TimeType timeType, const QLocale &locale) const { #if QT_CONFIG(icu) + auto lock = qt_unique_lock(s_icu_mutex); if (!m_icu) m_icu = new QIcuTimeZonePrivate(m_id); // TODO small risk may not match if tran times differ due to outdated files // TODO Some valid TZ names are not valid ICU names, use translation table? if (m_icu->isValid()) return m_icu->displayName(timeType, nameType, locale); + lock.unlock(); #else Q_UNUSED(timeType) Q_UNUSED(nameType) @@ -1285,6 +1292,11 @@ private: QByteArray QTzTimeZonePrivate::systemTimeZoneId() const { + return staticSystemTimeZoneId(); +} + +QByteArray QTzTimeZonePrivate::staticSystemTimeZoneId() +{ // Check TZ env var first, if not populated try find it QByteArray ianaId = qgetenv("TZ"); |