summaryrefslogtreecommitdiff
path: root/deps/icu-small/source/i18n/timezone.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'deps/icu-small/source/i18n/timezone.cpp')
-rw-r--r--deps/icu-small/source/i18n/timezone.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/deps/icu-small/source/i18n/timezone.cpp b/deps/icu-small/source/i18n/timezone.cpp
index 70169b5c1f..b90b78614a 100644
--- a/deps/icu-small/source/i18n/timezone.cpp
+++ b/deps/icu-small/source/i18n/timezone.cpp
@@ -527,6 +527,8 @@ TimeZone::detectHostTimeZone()
// -------------------------------------
+static UMutex gDefaultZoneMutex;
+
/**
* Initialize DEFAULT_ZONE from the system default time zone.
* Upon return, DEFAULT_ZONE will not be NULL, unless operator new()
@@ -536,6 +538,7 @@ static void U_CALLCONV initDefault()
{
ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
+ Mutex lock(&gDefaultZoneMutex);
// If setDefault() has already been called we can skip getting the
// default zone information from the system.
if (DEFAULT_ZONE != NULL) {
@@ -557,9 +560,6 @@ static void U_CALLCONV initDefault()
TimeZone *default_zone = TimeZone::detectHostTimeZone();
- // The only way for DEFAULT_ZONE to be non-null at this point is if the user
- // made a thread-unsafe call to setDefault() or adoptDefault() in another
- // thread while this thread was doing something that required getting the default.
U_ASSERT(DEFAULT_ZONE == NULL);
DEFAULT_ZONE = default_zone;
@@ -571,7 +571,10 @@ TimeZone* U_EXPORT2
TimeZone::createDefault()
{
umtx_initOnce(gDefaultZoneInitOnce, initDefault);
- return (DEFAULT_ZONE != NULL) ? DEFAULT_ZONE->clone() : NULL;
+ {
+ Mutex lock(&gDefaultZoneMutex);
+ return (DEFAULT_ZONE != NULL) ? DEFAULT_ZONE->clone() : NULL;
+ }
}
// -------------------------------------
@@ -581,9 +584,12 @@ TimeZone::adoptDefault(TimeZone* zone)
{
if (zone != NULL)
{
- TimeZone *old = DEFAULT_ZONE;
- DEFAULT_ZONE = zone;
- delete old;
+ {
+ Mutex lock(&gDefaultZoneMutex);
+ TimeZone *old = DEFAULT_ZONE;
+ DEFAULT_ZONE = zone;
+ delete old;
+ }
ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
}
}