+ UBool isOnlyLocale;
+ UMTX_CHECK(NULL, (gDefaultLocale == NULL), isOnlyLocale);
+ if (isOnlyLocale) {
+ // We haven't seen this locale id before.
+ // Create a new Locale object for it.
+ Locale *newFirstDefault = new Locale(Locale::eBOGUS);
+ if (newFirstDefault == NULL) {
+ // No way to report errors from here.
+ return;
+ }
+ newFirstDefault->init(localeNameBuf, FALSE);
+ umtx_lock(NULL);
+ if (gDefaultLocale == NULL) {
+ gDefaultLocale = newFirstDefault; // Assignment to gDefaultLocale must happen inside mutex
+ newFirstDefault = NULL;
+ ucln_common_registerCleanup(UCLN_COMMON_LOCALE, locale_cleanup);
+ }
+ // Else some other thread raced us through here, and set the new Locale.
+ // Use the hash table next.
+ umtx_unlock(NULL);
+ if (newFirstDefault == NULL) {
+ // We were successful in setting the locale, and we were the first one to set it.
+ return;
+ }
+ // else start using the hash table.
+ }
+
+ // Lazy creation of the hash table itself, if needed.
+ UBool hashTableNeedsInit;
+ UMTX_CHECK(NULL, (gDefaultLocalesHashT == NULL), hashTableNeedsInit);