comparison modules/javafx.web/src/main/native/Source/ThirdParty/icu/source/common/resbund.cpp @ 11348:6744f504e684

8231310: Add .jcheck/conf to jfx git repo Reviewed-by: prr, jvos
author kcr
date Tue, 01 Oct 2019 05:28:24 -0700
parents fee4ef5c87df
children
comparison
equal deleted inserted replaced
0:a839f66eb3ea 1:0cad1fb9a896
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
1 /* 3 /*
2 ********************************************************************** 4 **********************************************************************
3 * Copyright (C) 1997-2011, International Business Machines 5 * Copyright (C) 1997-2013, International Business Machines
4 * Corporation and others. All Rights Reserved. 6 * Corporation and others. All Rights Reserved.
5 ********************************************************************** 7 **********************************************************************
6 * 8 *
7 * File resbund.cpp 9 * File resbund.cpp
8 * 10 *
46 ****************************************************************************** 48 ******************************************************************************
47 */ 49 */
48 50
49 #include "unicode/utypes.h" 51 #include "unicode/utypes.h"
50 #include "unicode/resbund.h" 52 #include "unicode/resbund.h"
53
54 #include "mutex.h"
55 #include "uassert.h"
51 #include "umutex.h" 56 #include "umutex.h"
52 57
53 #include "uresimp.h" 58 #include "uresimp.h"
54 59
55 U_NAMESPACE_BEGIN 60 U_NAMESPACE_BEGIN
214 } 219 }
215 if(fResource != 0) { 220 if(fResource != 0) {
216 ures_close(fResource); 221 ures_close(fResource);
217 fResource = NULL; 222 fResource = NULL;
218 } 223 }
224 if (fLocale != NULL) {
225 delete fLocale;
226 fLocale = NULL;
227 }
219 UErrorCode status = U_ZERO_ERROR; 228 UErrorCode status = U_ZERO_ERROR;
220 if (other.fResource) { 229 if (other.fResource) {
221 fResource = ures_copyResb(0, other.fResource, &status); 230 fResource = ures_copyResb(0, other.fResource, &status);
222 } else { 231 } else {
223 /* Copying a bad resource bundle */ 232 /* Copying a bad resource bundle */
365 374
366 void ResourceBundle::getVersion(UVersionInfo versionInfo) const { 375 void ResourceBundle::getVersion(UVersionInfo versionInfo) const {
367 ures_getVersion(fResource, versionInfo); 376 ures_getVersion(fResource, versionInfo);
368 } 377 }
369 378
370 const Locale &ResourceBundle::getLocale(void) const 379 static UMutex gLocaleLock = U_MUTEX_INITIALIZER;
371 { 380 const Locale &ResourceBundle::getLocale(void) const {
372 UBool needInit; 381 Mutex lock(&gLocaleLock);
373 UMTX_CHECK(NULL, (fLocale == NULL), needInit); 382 if (fLocale != NULL) {
374 if(needInit) { 383 return *fLocale;
375 UErrorCode status = U_ZERO_ERROR; 384 }
376 const char *localeName = ures_getLocaleInternal(fResource, &status); 385 UErrorCode status = U_ZERO_ERROR;
377 Locale *tLocale = new Locale(localeName); 386 const char *localeName = ures_getLocaleInternal(fResource, &status);
378 // Null pointer check 387 ResourceBundle *ncThis = const_cast<ResourceBundle *>(this);
379 if (tLocale == NULL) { 388 ncThis->fLocale = new Locale(localeName);
380 return Locale::getDefault(); // Return default locale if one could not be created. 389 return ncThis->fLocale != NULL ? *ncThis->fLocale : Locale::getDefault();
381 }
382 umtx_lock(NULL);
383 ResourceBundle *me = (ResourceBundle *)this; // semantically const
384 if (me->fLocale == NULL) {
385 me->fLocale = tLocale;
386 tLocale = NULL;
387 }
388 umtx_unlock(NULL);
389 delete tLocale;
390 }
391 return *fLocale;
392 } 390 }
393 391
394 const Locale ResourceBundle::getLocale(ULocDataLocaleType type, UErrorCode &status) const 392 const Locale ResourceBundle::getLocale(ULocDataLocaleType type, UErrorCode &status) const
395 { 393 {
396 return ures_getLocaleByType(fResource, type, &status); 394 return ures_getLocaleByType(fResource, type, &status);
397 } 395 }
398 396
397 U_NAMESPACE_END
399 //eof 398 //eof
400 U_NAMESPACE_END