diff modules/javafx.web/src/main/native/Source/ThirdParty/icu/source/common/resbund.cpp @ 11038:20a8447c71c6

8207159: Update ICU to version 62.1 Reviewed-by: mbilla, kcr, ghb
author arajkumar
date Fri, 24 Aug 2018 15:06:40 +0530
parents fee4ef5c87df
children
line wrap: on
line diff
--- a/modules/javafx.web/src/main/native/Source/ThirdParty/icu/source/common/resbund.cpp	Thu Aug 23 04:06:04 2018 -0700
+++ b/modules/javafx.web/src/main/native/Source/ThirdParty/icu/source/common/resbund.cpp	Fri Aug 24 15:06:40 2018 +0530
@@ -1,6 +1,8 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 **********************************************************************
-*   Copyright (C) 1997-2011, International Business Machines
+*   Copyright (C) 1997-2013, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 *
@@ -48,6 +50,9 @@
 
 #include "unicode/utypes.h"
 #include "unicode/resbund.h"
+
+#include "mutex.h"
+#include "uassert.h"
 #include "umutex.h"
 
 #include "uresimp.h"
@@ -216,6 +221,10 @@
         ures_close(fResource);
         fResource = NULL;
     }
+    if (fLocale != NULL) {
+        delete fLocale;
+        fLocale = NULL;
+    }
     UErrorCode status = U_ZERO_ERROR;
     if (other.fResource) {
         fResource = ures_copyResb(0, other.fResource, &status);
@@ -367,28 +376,17 @@
     ures_getVersion(fResource, versionInfo);
 }
 
-const Locale &ResourceBundle::getLocale(void) const
-{
-    UBool needInit;
-    UMTX_CHECK(NULL, (fLocale == NULL), needInit);
-    if(needInit) {
-        UErrorCode status = U_ZERO_ERROR;
-        const char *localeName = ures_getLocaleInternal(fResource, &status);
-        Locale  *tLocale = new Locale(localeName);
-        // Null pointer check
-        if (tLocale == NULL) {
-            return Locale::getDefault(); // Return default locale if one could not be created.
-        }
-        umtx_lock(NULL);
-        ResourceBundle *me = (ResourceBundle *)this; // semantically const
-        if (me->fLocale == NULL) {
-            me->fLocale = tLocale;
-            tLocale = NULL;
-        }
-        umtx_unlock(NULL);
-        delete tLocale;
+static UMutex gLocaleLock = U_MUTEX_INITIALIZER;
+const Locale &ResourceBundle::getLocale(void) const {
+    Mutex lock(&gLocaleLock);
+    if (fLocale != NULL) {
+        return *fLocale;
     }
-    return *fLocale;
+    UErrorCode status = U_ZERO_ERROR;
+    const char *localeName = ures_getLocaleInternal(fResource, &status);
+    ResourceBundle *ncThis = const_cast<ResourceBundle *>(this);
+    ncThis->fLocale = new Locale(localeName);
+    return ncThis->fLocale != NULL ? *ncThis->fLocale : Locale::getDefault();
 }
 
 const Locale ResourceBundle::getLocale(ULocDataLocaleType type, UErrorCode &status) const
@@ -396,5 +394,5 @@
   return ures_getLocaleByType(fResource, type, &status);
 }
 
+U_NAMESPACE_END
 //eof
-U_NAMESPACE_END