+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
******************************************************************************
* Copyright (C) 2007-2014, International Business Machines Corporation
// --- The cache --
-static UMutex astroLock = U_MUTEX_INITIALIZER; // pod bay door lock
+static icu::UMutex *astroLock() { // Protects access to gChineseCalendarAstro.
+ static icu::UMutex *m = STATIC_NEW(icu::UMutex);
+ return m;
+}
static icu::CalendarAstronomer *gChineseCalendarAstro = NULL;
+
+// Lazy Creation & Access synchronized by class CalendarCache with a mutex.
static icu::CalendarCache *gChineseCalendarWinterSolsticeCache = NULL;
static icu::CalendarCache *gChineseCalendarNewYearCache = NULL;
+
static icu::TimeZone *gChineseCalendarZoneAstroCalc = NULL;
static icu::UInitOnce gChineseCalendarZoneAstroCalcInitOnce = U_INITONCE_INITIALIZER;
// PST 1298 with a final result of Dec 14 10:31:59 PST 1299.
double ms = daysToMillis(Grego::fieldsToDay(gyear, UCAL_DECEMBER, 1));
- umtx_lock(&astroLock);
+ umtx_lock(astroLock());
if(gChineseCalendarAstro == NULL) {
gChineseCalendarAstro = new CalendarAstronomer();
ucln_i18n_registerCleanup(UCLN_I18N_CHINESE_CALENDAR, calendar_chinese_cleanup);
}
gChineseCalendarAstro->setTime(ms);
UDate solarLong = gChineseCalendarAstro->getSunTime(CalendarAstronomer::WINTER_SOLSTICE(), TRUE);
- umtx_unlock(&astroLock);
+ umtx_unlock(astroLock());
// Winter solstice is 270 degrees solar longitude aka Dongzhi
cacheValue = (int32_t)millisToDays(solarLong);
// we are out of its range and need to use the full machinery.
UDate newMoon = CalendarAstronomer::getNewMoonTimeInRange(ms, after);
if (newMoon == 0.0) {
- umtx_lock(&astroLock);
+ umtx_lock(astroLock());
if(gChineseCalendarAstro == NULL) {
gChineseCalendarAstro = new CalendarAstronomer();
ucln_i18n_registerCleanup(UCLN_I18N_CHINESE_CALENDAR, calendar_chinese_cleanup);
}
gChineseCalendarAstro->setTime(ms);
newMoon = gChineseCalendarAstro->getMoonTime(CalendarAstronomer::NEW_MOON(), after);
- umtx_unlock(&astroLock);
+ umtx_unlock(astroLock());
}
-
+
return (int32_t) millisToDays(newMoon);
}