]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/rbtz.cpp
ICU-511.25.tar.gz
[apple/icu.git] / icuSources / i18n / rbtz.cpp
index c53ccd7dba1a20da20e173e5be275093d369e9f7..6abc6d1e6516e9af0cf21422787e25dd7e2c0fde 100644 (file)
@@ -1,11 +1,11 @@
 /*
 *******************************************************************************
-* Copyright (C) 2007-2011, International Business Machines Corporation and
+* Copyright (C) 2007-2013, International Business Machines Corporation and
 * others. All Rights Reserved.
 *******************************************************************************
 */
 
-#include <typeinfo>  // for 'typeid' to work
+#include "utypeinfo.h"  // for 'typeid' to work
 
 #include "unicode/utypes.h"
 
@@ -16,6 +16,7 @@
 #include "uvector.h"
 #include "gregoimp.h"
 #include "cmemory.h"
+#include "umutex.h"
 
 U_NAMESPACE_BEGIN
 
@@ -143,6 +144,25 @@ RuleBasedTimeZone::addTransitionRule(TimeZoneRule* rule, UErrorCode& status) {
     fUpToDate = FALSE;
 }
 
+static UMutex gLock = U_MUTEX_INITIALIZER;
+
+void
+RuleBasedTimeZone::completeConst(UErrorCode& status) const {
+    if (U_FAILURE(status)) {
+        return;
+    }
+    UBool updated;
+    UMTX_CHECK(&gLock, fUpToDate, updated);
+    if (!updated) {
+        umtx_lock(&gLock);
+        if (!fUpToDate) {
+            RuleBasedTimeZone *ncThis = const_cast<RuleBasedTimeZone*>(this);
+            ncThis->complete(status);
+        }
+        umtx_unlock(&gLock);
+    }
+}
+
 void
 RuleBasedTimeZone::complete(UErrorCode& status) {
     if (U_FAILURE(status)) {
@@ -387,7 +407,7 @@ RuleBasedTimeZone::getOffset(UDate date, UBool local, int32_t& rawOffset,
 
 void
 RuleBasedTimeZone::getOffsetFromLocal(UDate date, int32_t nonExistingTimeOpt, int32_t duplicatedTimeOpt,
-                                      int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) /*const*/ {
+                                      int32_t& rawOffset, int32_t& dstOffset, UErrorCode& status) const {
     getOffsetInternal(date, TRUE, nonExistingTimeOpt, duplicatedTimeOpt, rawOffset, dstOffset, status);
 }
 
@@ -525,9 +545,9 @@ RuleBasedTimeZone::hasSameRules(const TimeZone& other) const {
 }
 
 UBool
-RuleBasedTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) /*const*/ {
+RuleBasedTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const {
     UErrorCode status = U_ZERO_ERROR;
-    complete(status);
+    completeConst(status);
     if (U_FAILURE(status)) {
         return FALSE;
     }
@@ -544,9 +564,9 @@ RuleBasedTimeZone::getNextTransition(UDate base, UBool inclusive, TimeZoneTransi
 }
 
 UBool
-RuleBasedTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) /*const*/ {
+RuleBasedTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTransition& result) const {
     UErrorCode status = U_ZERO_ERROR;
-    complete(status);
+    completeConst(status);
     if (U_FAILURE(status)) {
         return FALSE;
     }
@@ -563,7 +583,7 @@ RuleBasedTimeZone::getPreviousTransition(UDate base, UBool inclusive, TimeZoneTr
 }
 
 int32_t
-RuleBasedTimeZone::countTransitionRules(UErrorCode& /*status*/) /*const*/ {
+RuleBasedTimeZone::countTransitionRules(UErrorCode& /*status*/) const {
     int32_t count = 0;
     if (fHistoricRules != NULL) {
         count += fHistoricRules->size();
@@ -578,7 +598,7 @@ void
 RuleBasedTimeZone::getTimeZoneRules(const InitialTimeZoneRule*& initial,
                                     const TimeZoneRule* trsrules[],
                                     int32_t& trscount,
-                                    UErrorCode& status) /*const*/ {
+                                    UErrorCode& status) const {
     if (U_FAILURE(status)) {
         return;
     }