#include "unicode/utf16.h"
#include "tznames_impl.h"
+#include "bytesinkutil.h"
+#include "charstr.h"
#include "cmemory.h"
#include "cstring.h"
#include "uassert.h"
#include "mutex.h"
#include "resource.h"
+#include "ulocimp.h"
#include "uresimp.h"
#include "ureslocs.h"
#include "zonemeta.h"
static const char* TZDBNAMES_KEYS[] = {"ss", "sd"};
static const int32_t TZDBNAMES_KEYS_SIZE = UPRV_LENGTHOF(TZDBNAMES_KEYS);
-static UMutex *gDataMutex() {
- static UMutex *m = STATIC_NEW(UMutex);
- return m;
-}
+static UMutex gDataMutex;
static UHashtable* gTZDBNamesMap = NULL;
static icu::UInitOnce gTZDBNamesMapInitOnce = U_INITONCE_INITIALIZER;
// Don't do unless it's really required.
// Mutex for protecting the lazy creation of the Trie node structure on the first call to search().
- static UMutex *TextTrieMutex = STATIC_NEW(UMutex);
+ static UMutex TextTrieMutex;
- Mutex lock(TextTrieMutex);
+ Mutex lock(&TextTrieMutex);
if (fLazyContents != NULL) {
TextTrieMap *nonConstThis = const_cast<TextTrieMap *>(this);
nonConstThis->buildTrie(status);
return FALSE;
}
-TimeZoneNames*
+TimeZoneNamesImpl*
TimeZoneNamesImpl::clone() const {
UErrorCode status = U_ZERO_ERROR;
return new TimeZoneNamesImpl(fLocale, status);
TimeZoneNamesImpl *nonConstThis = const_cast<TimeZoneNamesImpl *>(this);
{
- Mutex lock(gDataMutex());
+ Mutex lock(&gDataMutex);
UErrorCode status = U_ZERO_ERROR;
znames = nonConstThis->loadMetaZoneNames(mzID, status);
if (U_FAILURE(status)) { return name; }
TimeZoneNamesImpl *nonConstThis = const_cast<TimeZoneNamesImpl *>(this);
{
- Mutex lock(gDataMutex());
+ Mutex lock(&gDataMutex);
UErrorCode status = U_ZERO_ERROR;
tznames = nonConstThis->loadTimeZoneNames(tzID, status);
if (U_FAILURE(status)) { return name; }
TimeZoneNamesImpl *nonConstThis = const_cast<TimeZoneNamesImpl *>(this);
{
- Mutex lock(gDataMutex());
+ Mutex lock(&gDataMutex);
UErrorCode status = U_ZERO_ERROR;
tznames = nonConstThis->loadTimeZoneNames(tzID, status);
if (U_FAILURE(status)) { return name; }
// Synchronize so that data is not loaded multiple times.
// TODO: Consider more fine-grained synchronization.
{
- Mutex lock(gDataMutex());
+ Mutex lock(&gDataMutex);
// First try of lookup.
matches = doFind(handler, text, start, status);
if (U_FAILURE(status)) return;
{
- Mutex lock(gDataMutex());
+ Mutex lock(&gDataMutex);
internalLoadAllDisplayNames(status);
}
}
// Load the time zone strings
{
- Mutex lock(gDataMutex());
+ Mutex lock(&gDataMutex);
tznames = (void*) nonConstThis->loadTimeZoneNames(tzID, status);
if (U_FAILURE(status)) { return; }
}
} else {
// Load the meta zone strings
// Mutex is scoped to the "else" statement
- Mutex lock(gDataMutex());
+ Mutex lock(&gDataMutex);
mznames = (void*) nonConstThis->loadMetaZoneNames(mzID, status);
if (U_FAILURE(status)) { return; }
// Note: when the metazone doesn't exist, in Java, loadMetaZoneNames returns
int32_t regionLen = static_cast<int32_t>(uprv_strlen(region));
if (regionLen == 0) {
UErrorCode status = U_ZERO_ERROR;
- char loc[ULOC_FULLNAME_CAPACITY];
- uloc_addLikelySubtags(fLocale.getName(), loc, sizeof(loc), &status);
- regionLen = uloc_getCountry(loc, fRegion, sizeof(fRegion), &status);
+ CharString loc;
+ {
+ CharStringByteSink sink(&loc);
+ ulocimp_addLikelySubtags(fLocale.getName(), sink, &status);
+ }
+ regionLen = uloc_getCountry(loc.data(), fRegion, sizeof(fRegion), &status);
if (U_SUCCESS(status) && regionLen < (int32_t)sizeof(fRegion)) {
useWorld = FALSE;
}
return FALSE;
}
-TimeZoneNames*
+TZDBTimeZoneNames*
TZDBTimeZoneNames::clone() const {
return new TZDBTimeZoneNames(fLocale);
}
U_ASSERT(status == U_ZERO_ERROR); // already checked length above
mzIDKey[mzID.length()] = 0;
- static UMutex *gTZDBNamesMapLock = STATIC_NEW(UMutex);
- umtx_lock(gTZDBNamesMapLock);
+ static UMutex gTZDBNamesMapLock;
+ umtx_lock(&gTZDBNamesMapLock);
{
void *cacheVal = uhash_get(gTZDBNamesMap, mzIDKey);
if (cacheVal == NULL) {
tzdbNames = (TZDBNames *)cacheVal;
}
}
- umtx_unlock(gTZDBNamesMapLock);
+ umtx_unlock(&gTZDBNamesMapLock);
return tzdbNames;
}