+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
-* Copyright (C) 2003 - 2008, International Business Machines Corporation and *
-* others. All Rights Reserved. *
+* Copyright (C) 2003 - 2013, International Business Machines Corporation and
+* others. All Rights Reserved.
*******************************************************************************
*/
}
void
-EthiopicCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status)
+EthiopicCalendar::handleComputeFields(int32_t julianDay, UErrorCode &/*status*/)
{
int32_t eyear, month, day, era, year;
jdToCE(julianDay, getJDEpochOffset(), eyear, month, day);
return CECalendar::handleGetLimit(field, limitType);
}
-const UDate EthiopicCalendar::fgSystemDefaultCentury = DBL_MIN;
-const int32_t EthiopicCalendar::fgSystemDefaultCenturyYear = -1;
+/**
+ * The system maintains a static default century start date and Year. They are
+ * initialized the first time they are used. Once the system default century date
+ * and year are set, they do not change.
+ */
+static UDate gSystemDefaultCenturyStart = DBL_MIN;
+static int32_t gSystemDefaultCenturyStartYear = -1;
+static icu::UInitOnce gSystemDefaultCenturyInit = U_INITONCE_INITIALIZER;
-UDate EthiopicCalendar::fgSystemDefaultCenturyStart = DBL_MIN;
-int32_t EthiopicCalendar::fgSystemDefaultCenturyStartYear = -1;
+static void U_CALLCONV initializeSystemDefaultCentury()
+{
+ UErrorCode status = U_ZERO_ERROR;
+ EthiopicCalendar calendar(Locale("@calendar=ethiopic"), status);
+ if (U_SUCCESS(status)) {
+ calendar.setTime(Calendar::getNow(), status);
+ calendar.add(UCAL_YEAR, -80, status);
+
+ gSystemDefaultCenturyStart = calendar.getTime(status);
+ gSystemDefaultCenturyStartYear = calendar.get(UCAL_YEAR, status);
+ }
+ // We have no recourse upon failure unless we want to propagate the failure
+ // out.
+}
UDate
EthiopicCalendar::defaultCenturyStart() const
{
- initializeSystemDefaultCentury();
- return fgSystemDefaultCenturyStart;
+ // lazy-evaluate systemDefaultCenturyStart
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
+ return gSystemDefaultCenturyStart;
}
int32_t
EthiopicCalendar::defaultCenturyStartYear() const
{
- initializeSystemDefaultCentury();
+ // lazy-evaluate systemDefaultCenturyStartYear
+ umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury);
if (isAmeteAlemEra()) {
- return fgSystemDefaultCenturyStartYear + AMETE_MIHRET_DELTA;
+ return gSystemDefaultCenturyStartYear + AMETE_MIHRET_DELTA;
}
- return fgSystemDefaultCenturyStartYear;
+ return gSystemDefaultCenturyStartYear;
}
-void
-EthiopicCalendar::initializeSystemDefaultCentury()
-{
- // lazy-evaluate systemDefaultCenturyStart
- UBool needsUpdate;
- UMTX_CHECK(NULL, (fgSystemDefaultCenturyStart == fgSystemDefaultCentury), needsUpdate);
-
- if (!needsUpdate) {
- return;
- }
-
- UErrorCode status = U_ZERO_ERROR;
-
- EthiopicCalendar calendar(Locale("@calendar=ethiopic"), status);
- if (U_SUCCESS(status)) {
- calendar.setTime(Calendar::getNow(), status);
- calendar.add(UCAL_YEAR, -80, status);
- UDate newStart = calendar.getTime(status);
- int32_t newYear = calendar.get(UCAL_YEAR, status);
- {
- umtx_lock(NULL);
- fgSystemDefaultCenturyStart = newStart;
- fgSystemDefaultCenturyStartYear = newYear;
- umtx_unlock(NULL);
- }
- }
- // We have no recourse upon failure unless we want to propagate the failure
- // out.
-}
int32_t
EthiopicCalendar::getJDEpochOffset() const