X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/729e4ab9bc6618bc3d8a898e575df7f4019e29ca..f3c0d7a59d99c2a94c6b8822291f0e42be3773c9:/icuSources/i18n/coptccal.cpp diff --git a/icuSources/i18n/coptccal.cpp b/icuSources/i18n/coptccal.cpp index 84bbad79..ba2040dc 100644 --- a/icuSources/i18n/coptccal.cpp +++ b/icuSources/i18n/coptccal.cpp @@ -1,7 +1,9 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* -* Copyright (C) 2003 - 2009, International Business Machines Corporation and * -* others. All Rights Reserved. * +* Copyright (C) 2003 - 2013, International Business Machines Corporation and +* others. All Rights Reserved. ******************************************************************************* */ @@ -94,62 +96,46 @@ CopticCalendar::handleComputeFields(int32_t julianDay, UErrorCode &/*status*/) internalSet(UCAL_DAY_OF_YEAR, (30 * month) + day); } -const UDate CopticCalendar::fgSystemDefaultCentury = DBL_MIN; -const int32_t CopticCalendar::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 CopticCalendar::fgSystemDefaultCenturyStart = DBL_MIN; -int32_t CopticCalendar::fgSystemDefaultCenturyStartYear = -1; + +static void U_CALLCONV initializeSystemDefaultCentury() { + UErrorCode status = U_ZERO_ERROR; + CopticCalendar calendar(Locale("@calendar=coptic"), 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 CopticCalendar::defaultCenturyStart() const { - initializeSystemDefaultCentury(); - - // use defaultCenturyStart unless it's the flag value; - // then use systemDefaultCenturyStart - return fgSystemDefaultCenturyStart; + // lazy-evaluate systemDefaultCenturyStart + umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury); + return gSystemDefaultCenturyStart; } int32_t CopticCalendar::defaultCenturyStartYear() const -{ - initializeSystemDefaultCentury(); - - // use defaultCenturyStart unless it's the flag value; - // then use systemDefaultCenturyStart - return fgSystemDefaultCenturyStartYear; -} - -void -CopticCalendar::initializeSystemDefaultCentury() { // lazy-evaluate systemDefaultCenturyStart - UBool needsUpdate; - UMTX_CHECK(NULL, (fgSystemDefaultCenturyStart == fgSystemDefaultCentury), needsUpdate); - - if (!needsUpdate) { - return; - } - - UErrorCode status = U_ZERO_ERROR; - - CopticCalendar calendar(Locale("@calendar=coptic"), 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); - fgSystemDefaultCenturyStartYear = newYear; - fgSystemDefaultCenturyStart = newStart; - umtx_unlock(NULL); - } - } - // We have no recourse upon failure unless we want to propagate the failure - // out. + umtx_initOnce(gSystemDefaultCenturyInit, &initializeSystemDefaultCentury); + return gSystemDefaultCenturyStartYear; } + int32_t CopticCalendar::getJDEpochOffset() const {