Fix additional thread safety issue in timezone code
This is an update to the previous fix at
https://chromium-review.googlesource.com/c/chromium/deps/icu/+/1602037
It takes care of threading issue in initDefault in timezone.cpp as well.
See
https://logs.chromium.org/logs/v8/buildbucket/cr-buildbucket.appspot.com/8913891060019594592/+/steps/Check/0/logs/DateCache.AdoptDefaultMixed/0
Upstream bug: https://unicode-org.atlassian.net/browse/ICU-20595
upstream PR: https://github.com/unicode-org/icu/pull/649/
Bug: chromium:950851
Test: v8 unittests - DateCache:AdoptDefault*
Change-Id: Ifc215e02992050af5c55e1cc0208cff61112c9ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/deps/icu/+/1604257
Reviewed-by: Jungshik Shin <jshin@chromium.org>
diff --git a/patches/timezone.patch b/patches/timezone.patch
index d456d6f..bf7e172 100644
--- a/patches/timezone.patch
+++ b/patches/timezone.patch
@@ -1,12 +1,12 @@
diff --git a/source/i18n/timezone.cpp b/source/i18n/timezone.cpp
-index f129d8b6..f7b48273 100644
+index f129d8b6..32214d72 100644
--- a/source/i18n/timezone.cpp
+++ b/source/i18n/timezone.cpp
@@ -527,6 +527,11 @@ TimeZone::detectHostTimeZone()
// -------------------------------------
-+static UMutex *gMutex() {
++static UMutex *gDefaultZoneMutex() {
+ static UMutex* m = new UMutex();
+ return m;
+}
@@ -18,31 +18,32 @@
{
ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
-+ Mutex lock(gMutex());
++ Mutex lock(gDefaultZoneMutex());
// If setDefault() has already been called we can skip getting the
// default zone information from the system.
if (DEFAULT_ZONE != NULL) {
-@@ -571,7 +577,11 @@ TimeZone* U_EXPORT2
+@@ -571,7 +577,10 @@ TimeZone* U_EXPORT2
TimeZone::createDefault()
{
umtx_initOnce(gDefaultZoneInitOnce, initDefault);
- return (DEFAULT_ZONE != NULL) ? DEFAULT_ZONE->clone() : NULL;
-+ if (DEFAULT_ZONE == NULL) return NULL;
+ {
-+ Mutex lock(gMutex());
-+ return DEFAULT_ZONE->clone();
++ Mutex lock(gDefaultZoneMutex());
++ return (DEFAULT_ZONE != NULL) ? DEFAULT_ZONE->clone() : NULL;
+ }
}
// -------------------------------------
-@@ -582,8 +592,11 @@ TimeZone::adoptDefault(TimeZone* zone)
+@@ -581,9 +590,12 @@ TimeZone::adoptDefault(TimeZone* zone)
+ {
if (zone != NULL)
{
- TimeZone *old = DEFAULT_ZONE;
+- TimeZone *old = DEFAULT_ZONE;
- DEFAULT_ZONE = zone;
- delete old;
+ {
-+ Mutex lock(gMutex());
++ Mutex lock(gDefaultZoneMutex());
++ TimeZone *old = DEFAULT_ZONE;
+ DEFAULT_ZONE = zone;
+ delete old;
+ }
diff --git a/source/i18n/timezone.cpp b/source/i18n/timezone.cpp
index f7b4827..129e6a5 100644
--- a/source/i18n/timezone.cpp
+++ b/source/i18n/timezone.cpp
@@ -527,7 +527,7 @@
// -------------------------------------
-static UMutex *gMutex() {
+static UMutex *gDefaultZoneMutex() {
static UMutex* m = new UMutex();
return m;
}
@@ -541,7 +541,7 @@
{
ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
- Mutex lock(gMutex());
+ Mutex lock(gDefaultZoneMutex());
// If setDefault() has already been called we can skip getting the
// default zone information from the system.
if (DEFAULT_ZONE != NULL) {
@@ -577,10 +577,9 @@
TimeZone::createDefault()
{
umtx_initOnce(gDefaultZoneInitOnce, initDefault);
- if (DEFAULT_ZONE == NULL) return NULL;
{
- Mutex lock(gMutex());
- return DEFAULT_ZONE->clone();
+ Mutex lock(gDefaultZoneMutex());
+ return (DEFAULT_ZONE != NULL) ? DEFAULT_ZONE->clone() : NULL;
}
}
@@ -591,9 +590,9 @@
{
if (zone != NULL)
{
- TimeZone *old = DEFAULT_ZONE;
{
- Mutex lock(gMutex());
+ Mutex lock(gDefaultZoneMutex());
+ TimeZone *old = DEFAULT_ZONE;
DEFAULT_ZONE = zone;
delete old;
}