mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Bug 1583269 - Part 1: Remove custom patch to add thread-safety to icu::TimeZone::adoptDefault. r=jwalden
The custom patch is no longer necessary now that <https://unicode-org.atlassian.net/browse/ICU-20595> has been fixed. Also inline `icu::TimeZone::recreateDefault` into its sole caller and then remove this API addition. Differential Revision: https://phabricator.services.mozilla.com/D49441 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
f085f298dc
commit
da21d4fea0
@ -1,88 +0,0 @@
|
||||
# Adds threadsafe recreateDefault() method to ICU::Timezone.
|
||||
|
||||
diff --git a/intl/icu/source/i18n/timezone.cpp b/intl/icu/source/i18n/timezone.cpp
|
||||
--- a/intl/icu/source/i18n/timezone.cpp
|
||||
+++ b/intl/icu/source/i18n/timezone.cpp
|
||||
@@ -110,16 +110,22 @@ static const UChar WORLD[] = {0x30, 0x30, 0x31, 0x00}; /* "001" */
|
||||
static const UChar GMT_ID[] = {0x47, 0x4D, 0x54, 0x00}; /* "GMT" */
|
||||
static const UChar UNKNOWN_ZONE_ID[] = {0x45, 0x74, 0x63, 0x2F, 0x55, 0x6E, 0x6B, 0x6E, 0x6F, 0x77, 0x6E, 0x00}; /* "Etc/Unknown" */
|
||||
static const int32_t GMT_ID_LENGTH = 3;
|
||||
static const int32_t UNKNOWN_ZONE_ID_LENGTH = 11;
|
||||
|
||||
static icu::TimeZone* DEFAULT_ZONE = NULL;
|
||||
static icu::UInitOnce gDefaultZoneInitOnce = U_INITONCE_INITIALIZER;
|
||||
|
||||
+// Prevents DEFAULT_ZONE from being deleted while another thread is cloning it.
|
||||
+static icu::UMutex* defaultZoneMutex() {
|
||||
+ static icu::UMutex gDefaultZoneMutex = U_MUTEX_INITIALIZER;
|
||||
+ return &gDefaultZoneMutex;
|
||||
+}
|
||||
+
|
||||
alignas(icu::SimpleTimeZone)
|
||||
static char gRawGMT[sizeof(icu::SimpleTimeZone)];
|
||||
|
||||
alignas(icu::SimpleTimeZone)
|
||||
static char gRawUNKNOWN[sizeof(icu::SimpleTimeZone)];
|
||||
|
||||
static icu::UInitOnce gStaticZonesInitOnce = U_INITONCE_INITIALIZER;
|
||||
static UBool gStaticZonesInitialized = FALSE; // Whether the static zones are initialized and ready to use.
|
||||
@@ -566,26 +572,36 @@ static void U_CALLCONV initDefault()
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
TimeZone* U_EXPORT2
|
||||
TimeZone::createDefault()
|
||||
{
|
||||
umtx_initOnce(gDefaultZoneInitOnce, initDefault);
|
||||
+
|
||||
+ icu::Mutex mutex_lock(defaultZoneMutex());
|
||||
return (DEFAULT_ZONE != NULL) ? DEFAULT_ZONE->clone() : NULL;
|
||||
}
|
||||
|
||||
+void
|
||||
+TimeZone::recreateDefault()
|
||||
+{
|
||||
+ TimeZone *default_zone = TimeZone::detectHostTimeZone();
|
||||
+ adoptDefault(default_zone);
|
||||
+}
|
||||
+
|
||||
// -------------------------------------
|
||||
|
||||
void U_EXPORT2
|
||||
TimeZone::adoptDefault(TimeZone* zone)
|
||||
{
|
||||
if (zone != NULL)
|
||||
{
|
||||
+ icu::Mutex mutex_lock(defaultZoneMutex());
|
||||
TimeZone *old = DEFAULT_ZONE;
|
||||
DEFAULT_ZONE = zone;
|
||||
delete old;
|
||||
ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
|
||||
}
|
||||
}
|
||||
// -------------------------------------
|
||||
|
||||
diff --git a/intl/icu/source/i18n/unicode/timezone.h b/intl/icu/source/i18n/unicode/timezone.h
|
||||
--- a/intl/icu/source/i18n/unicode/timezone.h
|
||||
+++ b/intl/icu/source/i18n/unicode/timezone.h
|
||||
@@ -310,16 +310,19 @@ class U_I18N_API TimeZone : public UObject {
|
||||
*
|
||||
* @return A default TimeZone. Clients are responsible for deleting the time zone
|
||||
* object returned.
|
||||
* @see getUnknown
|
||||
* @stable ICU 2.0
|
||||
*/
|
||||
static TimeZone* U_EXPORT2 createDefault(void);
|
||||
|
||||
+#define ICU_TZ_HAS_RECREATE_DEFAULT
|
||||
+ static void U_EXPORT2 recreateDefault();
|
||||
+
|
||||
/**
|
||||
* Sets the default time zone (i.e., what's returned by createDefault()) to be the
|
||||
* specified time zone. If NULL is specified for the time zone, the default time
|
||||
* zone is set to the default host time zone. This call adopts the TimeZone object
|
||||
* passed in; the client is no longer responsible for deleting it.
|
||||
*
|
||||
* <p>This function is not thread safe. It is an error for multiple threads
|
||||
* to concurrently attempt to set the default time zone, or for any thread
|
@ -52,7 +52,6 @@ find ${icu_dir}/source/samples -name '*Makefile.in' -prune -or -type f -print |
|
||||
for patch in \
|
||||
bug-915735 \
|
||||
suppress-warnings.diff \
|
||||
bug-1172609-timezone-recreateDefault.diff \
|
||||
bug-1198952-workaround-make-3.82-bug.diff \
|
||||
bug-1433303-minimize-subtags.diff \
|
||||
; do
|
||||
|
@ -29,13 +29,9 @@
|
||||
#if ENABLE_INTL_API && !MOZ_SYSTEM_ICU
|
||||
# include "unicode/basictz.h"
|
||||
# include "unicode/locid.h"
|
||||
#endif /* ENABLE_INTL_API && !MOZ_SYSTEM_ICU */
|
||||
|
||||
#if ENABLE_INTL_API && (!MOZ_SYSTEM_ICU || defined(ICU_TZ_HAS_RECREATE_DEFAULT))
|
||||
# include "unicode/timezone.h"
|
||||
# include "unicode/unistr.h"
|
||||
#endif /* ENABLE_INTL_API && (!MOZ_SYSTEM_ICU || \
|
||||
defined(ICU_TZ_HAS_RECREATE_DEFAULT)) */
|
||||
#endif /* ENABLE_INTL_API && !MOZ_SYSTEM_ICU */
|
||||
|
||||
#include "util/Text.h"
|
||||
#include "vm/MutexIDs.h"
|
||||
@ -587,7 +583,7 @@ static bool IsOlsonCompatibleWindowsTimeZoneId(const char* tz) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#elif ENABLE_INTL_API && defined(ICU_TZ_HAS_RECREATE_DEFAULT)
|
||||
#elif ENABLE_INTL_API && !MOZ_SYSTEM_ICU
|
||||
static inline const char* TZContainsAbsolutePath(const char* tzVar) {
|
||||
// A TZ environment variable may be an absolute path. The path
|
||||
// format of TZ may begin with a colon. (ICU handles relative paths.)
|
||||
@ -724,16 +720,14 @@ static icu::UnicodeString ReadTimeZoneLink(const char* tz) {
|
||||
|
||||
return icu::UnicodeString(timeZone, timeZoneLen, US_INV);
|
||||
}
|
||||
#endif /* ENABLE_INTL_API && defined(ICU_TZ_HAS_RECREATE_DEFAULT) */
|
||||
#endif /* ENABLE_INTL_API && !MOZ_SYSTEM_ICU */
|
||||
|
||||
void js::ResyncICUDefaultTimeZone() {
|
||||
js::DateTimeInfo::resyncICUDefaultTimeZone();
|
||||
}
|
||||
|
||||
void js::DateTimeInfo::internalResyncICUDefaultTimeZone() {
|
||||
#if ENABLE_INTL_API && defined(ICU_TZ_HAS_RECREATE_DEFAULT)
|
||||
bool recreate = true;
|
||||
|
||||
#if ENABLE_INTL_API && !MOZ_SYSTEM_ICU
|
||||
if (const char* tz = std::getenv("TZ")) {
|
||||
icu::UnicodeString tzid;
|
||||
|
||||
@ -765,13 +759,13 @@ void js::DateTimeInfo::internalResyncICUDefaultTimeZone() {
|
||||
if (*newTimeZone != icu::TimeZone::getUnknown()) {
|
||||
// adoptDefault() takes ownership of the time zone.
|
||||
icu::TimeZone::adoptDefault(newTimeZone.release());
|
||||
recreate = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (recreate) {
|
||||
icu::TimeZone::recreateDefault();
|
||||
if (icu::TimeZone* defaultZone = icu::TimeZone::detectHostTimeZone()) {
|
||||
icu::TimeZone::adoptDefault(defaultZone);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user