-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_getLocale(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;