U_CDECL_END
U_NAMESPACE_BEGIN
-static UMutex gBreakEngineMutex = U_MUTEX_INITIALIZER;
-
const LanguageBreakEngine *
ICULanguageBreakFactory::getEngineFor(UChar32 c) {
const LanguageBreakEngine *lbe = NULL;
UErrorCode status = U_ZERO_ERROR;
+ static UMutex gBreakEngineMutex = U_MUTEX_INITIALIZER;
Mutex m(&gBreakEngineMutex);
if (fEngines == NULL) {
UCPMap *maps[UCHAR_INT_LIMIT - UCHAR_INT_START] = {};
-icu::UMutex cpMutex = U_MUTEX_INITIALIZER;
+icu::UMutex *cpMutex() {
+ static icu::UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
//----------------------------------------------------------------
// Inclusions list
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
return nullptr;
}
- Mutex m(&cpMutex);
+ Mutex m(cpMutex());
UnicodeSet *set = sets[property];
if (set == nullptr) {
sets[property] = set = makeSet(property, *pErrorCode);
*pErrorCode = U_ILLEGAL_ARGUMENT_ERROR;
return nullptr;
}
- Mutex m(&cpMutex);
+ Mutex m(cpMutex());
UCPMap *map = maps[property - UCHAR_INT_START];
if (map == nullptr) {
maps[property - UCHAR_INT_START] = map = makeMap(property, *pErrorCode);
#else
UObject* capitalizationBrkIter;
#endif
- static UMutex capitalizationBrkIterLock;
UnicodeString formatOpenParen;
UnicodeString formatReplaceOpenParen;
UnicodeString formatCloseParen;
struct CapitalizationContextSink;
};
-UMutex LocaleDisplayNamesImpl::capitalizationBrkIterLock = U_MUTEX_INITIALIZER;
-
LocaleDisplayNamesImpl::LocaleDisplayNamesImpl(const Locale& locale,
UDialectHandling dialectHandling)
: dialectHandling(dialectHandling)
if ( result.length() > 0 && u_islower(result.char32At(0)) && capitalizationBrkIter!= NULL &&
( capitalizationContext==UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE || fCapitalization[usage] ) ) {
// note fCapitalization[usage] won't be set unless capitalizationContext is UI_LIST_OR_MENU or STANDALONE
+ static UMutex capitalizationBrkIterLock = U_MUTEX_INITIALIZER;
Mutex lock(&capitalizationBrkIterLock);
result.toTitle(capitalizationBrkIter, locale, U_TITLECASE_NO_LOWERCASE | U_TITLECASE_NO_BREAK_ADJUSTMENT);
}
static UInitOnce gLocaleCacheInitOnce = U_INITONCE_INITIALIZER;
// gDefaultLocaleMutex protects all access to gDefaultLocalesHashT and gDefaultLocale.
-static UMutex gDefaultLocaleMutex = U_MUTEX_INITIALIZER;
+static UMutex *gDefaultLocaleMutex() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
static UHashtable *gDefaultLocalesHashT = NULL;
static Locale *gDefaultLocale = NULL;
Locale *locale_set_default_internal(const char *id, UErrorCode& status) {
// Synchronize this entire function.
- Mutex lock(&gDefaultLocaleMutex);
+ Mutex lock(gDefaultLocaleMutex());
UBool canonicalize = FALSE;
Locale::getDefault()
{
{
- Mutex lock(&gDefaultLocaleMutex);
+ Mutex lock(gDefaultLocaleMutex());
if (gDefaultLocale != NULL) {
return *gDefaultLocale;
}
UDate fakeClock_t0 = 0; /** Time to start the clock from **/
UDate fakeClock_dt = 0; /** Offset (fake time - real time) **/
UBool fakeClock_set = FALSE; /** True if fake clock has spun up **/
-static UMutex fakeClockMutex = U_MUTEX_INTIALIZER;
static UDate getUTCtime_real() {
struct timeval posixTime;
}
static UDate getUTCtime_fake() {
+ static UMutex fakeClockMutex = U_MUTEX_INTIALIZER;
umtx_lock(&fakeClockMutex);
if(!fakeClock_set) {
UDate real = getUTCtime_real();
ures_getVersion(fResource, versionInfo);
}
-static UMutex gLocaleLock = U_MUTEX_INITIALIZER;
const Locale &ResourceBundle::getLocale(void) const {
+ static UMutex gLocaleLock = U_MUTEX_INITIALIZER;
Mutex lock(&gLocaleLock);
if (fLocale != NULL) {
return *fLocale;
******************************************************************
*/
-static UMutex lock = U_MUTEX_INITIALIZER;
+static UMutex *lock() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
ICUService::ICUService()
: name()
ICUService::~ICUService()
{
{
- Mutex mutex(&lock);
+ Mutex mutex(lock());
clearCaches();
delete factories;
factories = NULL;
// if factory is not null, we're calling from within the mutex,
// and since some unix machines don't have reentrant mutexes we
// need to make sure not to try to lock it again.
- XMutex mutex(&lock, factory != NULL);
+ XMutex mutex(lock(), factory != NULL);
if (serviceCache == NULL) {
ncthis->serviceCache = new Hashtable(status);
}
{
- Mutex mutex(&lock);
+ Mutex mutex(lock());
const Hashtable* map = getVisibleIDMap(status);
if (map != NULL) {
ICUServiceKey* fallbackKey = createKey(matchID, status);
{
{
UErrorCode status = U_ZERO_ERROR;
- Mutex mutex(&lock);
+ Mutex mutex(lock());
const Hashtable* map = getVisibleIDMap(status);
if (map != NULL) {
ICUServiceFactory* f = (ICUServiceFactory*)map->get(id);
result.setDeleter(userv_deleteStringPair);
if (U_SUCCESS(status)) {
ICUService* ncthis = (ICUService*)this; // cast away semantic const
- Mutex mutex(&lock);
+ Mutex mutex(lock());
if (dnCache != NULL && dnCache->locale != locale) {
delete dnCache;
ICUService::registerFactory(ICUServiceFactory* factoryToAdopt, UErrorCode& status)
{
if (U_SUCCESS(status) && factoryToAdopt != NULL) {
- Mutex mutex(&lock);
+ Mutex mutex(lock());
if (factories == NULL) {
factories = new UVector(deleteUObject, NULL, status);
ICUServiceFactory *factory = (ICUServiceFactory*)rkey;
UBool result = FALSE;
if (factory != NULL && factories != NULL) {
- Mutex mutex(&lock);
+ Mutex mutex(lock());
if (factories->removeElement(factory)) {
clearCaches();
ICUService::reset()
{
{
- Mutex mutex(&lock);
+ Mutex mutex(lock());
reInitializeFactories();
clearCaches();
}
U_NAMESPACE_BEGIN
-static UMutex llock = U_MUTEX_INITIALIZER;
ICULocaleService::ICULocaleService()
: fallbackLocale(Locale::getDefault())
{
{
const Locale& loc = Locale::getDefault();
ICULocaleService* ncThis = (ICULocaleService*)this;
+ static UMutex llock = U_MUTEX_INITIALIZER;
{
Mutex mutex(&llock);
if (loc != fallbackLocale) {
EventListener::~EventListener() {}
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EventListener)
-static UMutex notifyLock = U_MUTEX_INITIALIZER;
+static UMutex *notifyLock() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
ICUNotifier::ICUNotifier(void)
: listeners(NULL)
ICUNotifier::~ICUNotifier(void) {
{
- Mutex lmx(¬ifyLock);
+ Mutex lmx(notifyLock());
delete listeners;
listeners = NULL;
}
}
if (acceptsListener(*l)) {
- Mutex lmx(¬ifyLock);
+ Mutex lmx(notifyLock());
if (listeners == NULL) {
listeners = new UVector(5, status);
} else {
}
{
- Mutex lmx(¬ifyLock);
+ Mutex lmx(notifyLock());
if (listeners != NULL) {
// identity equality check
for (int i = 0, e = listeners->size(); i < e; ++i) {
ICUNotifier::notifyChanged(void)
{
if (listeners != NULL) {
- Mutex lmx(¬ifyLock);
+ Mutex lmx(notifyLock());
if (listeners != NULL) {
for (int i = 0, e = listeners->size(); i < e; ++i) {
EventListener* el = (EventListener*)listeners->elementAt(i);
/*initializes some global variables */
static UHashtable *SHARED_DATA_HASHTABLE = NULL;
-static icu::UMutex cnvCacheMutex = U_MUTEX_INITIALIZER; /* Mutex for synchronizing cnv cache access. */
- /* Note: the global mutex is used for */
- /* reference count updates. */
+static icu::UMutex *cnvCacheMutex() { /* Mutex for synchronizing cnv cache access. */
+ static icu::UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
+/* Note: the global mutex is used for */
+/* reference count updates. */
static const char **gAvailableConverters = NULL;
static uint16_t gAvailableConverterCount = 0;
ucnv_unloadSharedDataIfReady(UConverterSharedData *sharedData)
{
if(sharedData != NULL && sharedData->isReferenceCounted) {
- umtx_lock(&cnvCacheMutex);
+ umtx_lock(cnvCacheMutex());
ucnv_unload(sharedData);
- umtx_unlock(&cnvCacheMutex);
+ umtx_unlock(cnvCacheMutex());
}
}
ucnv_incrementRefCount(UConverterSharedData *sharedData)
{
if(sharedData != NULL && sharedData->isReferenceCounted) {
- umtx_lock(&cnvCacheMutex);
+ umtx_lock(cnvCacheMutex());
sharedData->referenceCounter++;
- umtx_unlock(&cnvCacheMutex);
+ umtx_unlock(cnvCacheMutex());
}
}
pArgs->nestedLoads=1;
pArgs->pkg=NULL;
- umtx_lock(&cnvCacheMutex);
+ umtx_lock(cnvCacheMutex());
mySharedConverterData = ucnv_load(pArgs, err);
- umtx_unlock(&cnvCacheMutex);
+ umtx_unlock(cnvCacheMutex());
if (U_FAILURE (*err) || (mySharedConverterData == NULL))
{
return NULL;
* because the sequence of looking up in the cache + incrementing
* is protected by cnvCacheMutex.
*/
- umtx_lock(&cnvCacheMutex);
+ umtx_lock(cnvCacheMutex());
/*
* double loop: A delta/extension-only converter has a pointer to its base table's
* shared data; the first iteration of the outer loop may see the delta converter
}
}
} while(++i == 1 && remaining > 0);
- umtx_unlock(&cnvCacheMutex);
+ umtx_unlock(cnvCacheMutex());
UTRACE_DATA1(UTRACE_INFO, "ucnv_flushCache() exits with %d converters remaining", remaining);
}
algorithmicSharedData = getAlgorithmicTypeFromName(stackArgs.name);
- umtx_lock(&cnvCacheMutex);
+ umtx_lock(cnvCacheMutex());
gDefaultAlgorithmicSharedData = algorithmicSharedData;
gDefaultConverterContainsOption = containsOption;
ucnv_enableCleanup();
- umtx_unlock(&cnvCacheMutex);
+ umtx_unlock(cnvCacheMutex());
}
#endif
but ucnv_setDefaultName is not thread safe.
*/
{
- icu::Mutex lock(&cnvCacheMutex);
+ icu::Mutex lock(cnvCacheMutex());
name = gDefaultConverterName;
}
if(name==NULL) {
#if !UCONFIG_NO_SERVICE
struct CReg;
-static UMutex gCRegLock = U_MUTEX_INITIALIZER;
+static UMutex *gCRegLock() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
static CReg* gCRegHead = 0;
struct CReg : public icu::UMemory {
if (status && U_SUCCESS(*status) && _iso && _id) {
CReg* n = new CReg(_iso, _id);
if (n) {
- umtx_lock(&gCRegLock);
+ umtx_lock(gCRegLock());
if (!gCRegHead) {
/* register for the first time */
ucln_common_registerCleanup(UCLN_COMMON_CURRENCY, currency_cleanup);
}
n->next = gCRegHead;
gCRegHead = n;
- umtx_unlock(&gCRegLock);
+ umtx_unlock(gCRegLock());
return n;
}
*status = U_MEMORY_ALLOCATION_ERROR;
static UBool unreg(UCurrRegistryKey key) {
UBool found = FALSE;
- umtx_lock(&gCRegLock);
+ umtx_lock(gCRegLock());
CReg** p = &gCRegHead;
while (*p) {
p = &((*p)->next);
}
- umtx_unlock(&gCRegLock);
+ umtx_unlock(gCRegLock());
return found;
}
static const UChar* get(const char* id) {
const UChar* result = NULL;
- umtx_lock(&gCRegLock);
+ umtx_lock(gCRegLock());
CReg* p = gCRegHead;
/* register cleanup of the mutex */
}
p = p->next;
}
- umtx_unlock(&gCRegLock);
+ umtx_unlock(gCRegLock());
return result;
}
// It is a simple round-robin replacement strategy.
static int8_t currentCacheEntryIndex = 0;
-static UMutex gCurrencyCacheMutex = U_MUTEX_INITIALIZER;
+static UMutex *gCurrencyCacheMutex() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
// Cache deletion
static void
CurrencyNameStruct* currencySymbols = NULL;
CurrencyNameCacheEntry* cacheEntry = NULL;
- umtx_lock(&gCurrencyCacheMutex);
+ umtx_lock(gCurrencyCacheMutex());
// in order to handle racing correctly,
// not putting 'search' in a separate function.
int8_t found = -1;
cacheEntry = currCache[found];
++(cacheEntry->refCount);
}
- umtx_unlock(&gCurrencyCacheMutex);
+ umtx_unlock(gCurrencyCacheMutex());
if (found == -1) {
collectCurrencyNames(locale, ¤cyNames, &total_currency_name_count, ¤cySymbols, &total_currency_symbol_count, ec);
if (U_FAILURE(ec)) {
return NULL;
}
- umtx_lock(&gCurrencyCacheMutex);
+ umtx_lock(gCurrencyCacheMutex());
// check again.
for (int8_t i = 0; i < CURRENCY_NAME_CACHE_NUM; ++i) {
if (currCache[i]!= NULL &&
cacheEntry = currCache[found];
++(cacheEntry->refCount);
}
- umtx_unlock(&gCurrencyCacheMutex);
+ umtx_unlock(gCurrencyCacheMutex());
}
return cacheEntry;
}
static void releaseCacheEntry(CurrencyNameCacheEntry* cacheEntry) {
- umtx_lock(&gCurrencyCacheMutex);
+ umtx_lock(gCurrencyCacheMutex());
--(cacheEntry->refCount);
if (cacheEntry->refCount == 0) { // remove
deleteCacheEntry(cacheEntry);
}
- umtx_unlock(&gCurrencyCacheMutex);
+ umtx_unlock(gCurrencyCacheMutex());
}
U_CAPI void
*************************************************************************************************/
// The ICU global mutex. Used when ICU implementation code passes NULL for the mutex pointer.
-static UMutex globalMutex = U_MUTEX_INITIALIZER;
+static UMutex *globalMutex() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
U_CAPI void U_EXPORT2
umtx_lock(UMutex *mutex) {
if (mutex == nullptr) {
- mutex = &globalMutex;
+ mutex = globalMutex();
}
mutex->fMutex.lock();
}
umtx_unlock(UMutex* mutex)
{
if (mutex == nullptr) {
- mutex = &globalMutex;
+ mutex = globalMutex();
}
mutex->fMutex.unlock();
}
U_CAPI void U_EXPORT2
umtx_condWait(UConditionVar *cond, UMutex *mutex) {
if (mutex == nullptr) {
- mutex = &globalMutex;
+ mutex = globalMutex();
}
cond->fCV.wait(mutex->fMutex);
}
*
*************************************************************************************************/
-static std::mutex initMutex;
-static std::condition_variable initCondition;
+static std::mutex &initMutex() {
+ static std::mutex m;
+ return m;
+}
+
+static std::condition_variable &initCondition() {
+ static std::condition_variable cv;
+ return cv;
+}
// This function is called when a test of a UInitOnce::fState reveals that
//
U_COMMON_API UBool U_EXPORT2
umtx_initImplPreInit(UInitOnce &uio) {
- std::unique_lock<std::mutex> lock(initMutex);
+ std::unique_lock<std::mutex> lock(initMutex());
if (umtx_loadAcquire(uio.fState) == 0) {
umtx_storeRelease(uio.fState, 1);
while (umtx_loadAcquire(uio.fState) == 1) {
// Another thread is currently running the initialization.
// Wait until it completes.
- initCondition.wait(lock);
+ initCondition().wait(lock);
}
U_ASSERT(uio.fState == 2);
return false;
U_COMMON_API void U_EXPORT2
umtx_initImplPostInit(UInitOnce &uio) {
{
- std::unique_lock<std::mutex> lock(initMutex);
+ std::unique_lock<std::mutex> lock(initMutex());
umtx_storeRelease(uio.fState, 2);
}
- initCondition.notify_all();
+ initCondition().notify_all();
}
U_NAMESPACE_END
#include "umutex.h"
static icu::UnifiedCache *gCache = NULL;
-static icu::UMutex gCacheMutex = U_MUTEX_INITIALIZER;
-static icu::UConditionVar gInProgressValueAddedCond = U_CONDITION_INITIALIZER;
+static icu::UMutex *gCacheMutex() {
+ static icu::UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
+static icu::UConditionVar *gInProgressValueAddedCond() {
+ static icu::UConditionVar cv = U_CONDITION_INITIALIZER;
+ return &cv;
+}
static icu::UInitOnce gCacheInitOnce = U_INITONCE_INITIALIZER;
static const int32_t MAX_EVICT_ITERATIONS = 10;
status = U_ILLEGAL_ARGUMENT_ERROR;
return;
}
- Mutex lock(&gCacheMutex);
+ Mutex lock(gCacheMutex());
fMaxUnused = count;
fMaxPercentageOfInUse = percentageOfInUseItems;
}
int32_t UnifiedCache::unusedCount() const {
- Mutex lock(&gCacheMutex);
+ Mutex lock(gCacheMutex());
return uhash_count(fHashtable) - fNumValuesInUse;
}
int64_t UnifiedCache::autoEvictedCount() const {
- Mutex lock(&gCacheMutex);
+ Mutex lock(gCacheMutex());
return fAutoEvictedCount;
}
int32_t UnifiedCache::keyCount() const {
- Mutex lock(&gCacheMutex);
+ Mutex lock(gCacheMutex());
return uhash_count(fHashtable);
}
void UnifiedCache::flush() const {
- Mutex lock(&gCacheMutex);
+ Mutex lock(gCacheMutex());
// Use a loop in case cache items that are flushed held hard references to
// other cache items making those additional cache items eligible for
}
void UnifiedCache::handleUnreferencedObject() const {
- Mutex lock(&gCacheMutex);
+ Mutex lock(gCacheMutex());
--fNumValuesInUse;
_runEvictionSlice();
}
}
void UnifiedCache::dumpContents() const {
- Mutex lock(&gCacheMutex);
+ Mutex lock(gCacheMutex());
_dumpContents();
}
// Now all that should be left in the cache are entries that refer to
// each other and entries with hard references from outside the cache.
// Nothing we can do about these so proceed to wipe out the cache.
- Mutex lock(&gCacheMutex);
+ Mutex lock(gCacheMutex());
_flush(TRUE);
}
uhash_close(fHashtable);
const CacheKeyBase &key,
const SharedObject *&value,
UErrorCode &status) const {
- Mutex lock(&gCacheMutex);
+ Mutex lock(gCacheMutex());
const UHashElement *element = uhash_find(fHashtable, &key);
if (element != NULL && !_inProgress(element)) {
_fetch(element, value, status);
UErrorCode &status) const {
U_ASSERT(value == NULL);
U_ASSERT(status == U_ZERO_ERROR);
- Mutex lock(&gCacheMutex);
+ Mutex lock(gCacheMutex());
const UHashElement *element = uhash_find(fHashtable, &key);
// If the hash table contains an inProgress placeholder entry for this key,
// this means that another thread is currently constructing the value object.
// Loop, waiting for that construction to complete.
while (element != NULL && _inProgress(element)) {
- umtx_condWait(&gInProgressValueAddedCond, &gCacheMutex);
+ umtx_condWait(gInProgressValueAddedCond(), gCacheMutex());
element = uhash_find(fHashtable, &key);
}
// Tell waiting threads that we replace in-progress status with
// an error.
- umtx_condBroadcast(&gInProgressValueAddedCond);
+ umtx_condBroadcast(gInProgressValueAddedCond());
}
void UnifiedCache::_fetch(
static UHashtable *cache = NULL;
static icu::UInitOnce gCacheInitOnce;
-static UMutex resbMutex = U_MUTEX_INITIALIZER;
+static UMutex *resbMutex() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
/* INTERNAL: hashes an entry */
static int32_t U_CALLCONV hashEntry(const UHashTok parm) {
* Internal function
*/
static void entryIncrease(UResourceDataEntry *entry) {
- umtx_lock(&resbMutex);
+ umtx_lock(resbMutex());
entry->fCountExisting++;
while(entry->fParent != NULL) {
entry = entry->fParent;
entry->fCountExisting++;
}
- umtx_unlock(&resbMutex);
+ umtx_unlock(resbMutex());
}
/**
/*if shared data hasn't even been lazy evaluated yet
* return 0
*/
- umtx_lock(&resbMutex);
+ umtx_lock(resbMutex());
if (cache == NULL) {
- umtx_unlock(&resbMutex);
+ umtx_unlock(resbMutex());
return 0;
}
* got decremented by free_entry().
*/
} while(deletedMore);
- umtx_unlock(&resbMutex);
+ umtx_unlock(resbMutex());
return rbDeletedNum;
}
const UHashElement *e;
UResourceDataEntry *resB;
- umtx_lock(&resbMutex);
+ umtx_lock(resbMutex());
if (cache == NULL) {
- umtx_unlock(&resbMutex);
+ umtx_unlock(resbMutex());
fprintf(stderr,"%s:%d: RB Cache is NULL.\n", __FILE__, __LINE__);
return FALSE;
}
fprintf(stderr,"%s:%d: RB Cache still contains %d items.\n", __FILE__, __LINE__, uhash_count(cache));
- umtx_unlock(&resbMutex);
+ umtx_unlock(resbMutex());
return cacheNotEmpty;
}
}
}
- umtx_lock(&resbMutex);
+ umtx_lock(resbMutex());
{ /* umtx_lock */
/* We're going to skip all the locales that do not have any data */
r = findFirstExisting(path, name, &isRoot, &hasChopped, &isDefault, &intStatus);
}
} /* umtx_lock */
finishUnlock:
- umtx_unlock(&resbMutex);
+ umtx_unlock(resbMutex());
if(U_SUCCESS(*status)) {
if(intStatus != U_ZERO_ERROR) {
return NULL;
}
- umtx_lock(&resbMutex);
+ umtx_lock(resbMutex());
// findFirstExisting() without fallbacks.
UResourceDataEntry *r = init_entry(localeID, path, status);
if(U_SUCCESS(*status)) {
t1 = t1->fParent;
}
}
- umtx_unlock(&resbMutex);
+ umtx_unlock(resbMutex());
return r;
}
*/
static void entryClose(UResourceDataEntry *resB) {
- umtx_lock(&resbMutex);
+ umtx_lock(resbMutex());
entryCloseInt(resB);
- umtx_unlock(&resbMutex);
+ umtx_unlock(resbMutex());
}
/*
static UHashtable *SHARED_DATA_HASHTABLE = NULL;
static icu::UInitOnce gSharedDataInitOnce;
-static UMutex usprepMutex = U_MUTEX_INITIALIZER;
+static UMutex *usprepMutex() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
/* format version of spp file */
//static uint8_t formatVersion[4]={ 0, 0, 0, 0 };
* if shared data hasn't even been lazy evaluated yet
* return 0
*/
- umtx_lock(&usprepMutex);
+ umtx_lock(usprepMutex());
if (SHARED_DATA_HASHTABLE == NULL) {
- umtx_unlock(&usprepMutex);
+ umtx_unlock(usprepMutex());
return 0;
}
}
}
- umtx_unlock(&usprepMutex);
+ umtx_unlock(usprepMutex());
return deletedNum;
}
}
/* in the mutex block, set the data for this process */
- umtx_lock(&usprepMutex);
+ umtx_lock(usprepMutex());
if(profile->sprepData==NULL) {
profile->sprepData=dataMemory;
dataMemory=NULL;
} else {
p=(const int32_t *)udata_getMemory(profile->sprepData);
}
- umtx_unlock(&usprepMutex);
+ umtx_unlock(usprepMutex());
/* initialize some variables */
profile->mappingData=(uint16_t *)((uint8_t *)(p+_SPREP_INDEX_TOP)+profile->indexes[_SPREP_INDEX_TRIE_SIZE]);
stackKey.path = (char*) path;
/* fetch the data from the cache */
- umtx_lock(&usprepMutex);
+ umtx_lock(usprepMutex());
profile = (UStringPrepProfile*) (uhash_get(SHARED_DATA_HASHTABLE,&stackKey));
if(profile != NULL) {
profile->refCount++;
}
- umtx_unlock(&usprepMutex);
+ umtx_unlock(usprepMutex());
if(profile == NULL) {
/* else load the data and put the data in the cache */
return NULL;
}
- umtx_lock(&usprepMutex);
+ umtx_lock(usprepMutex());
// If another thread already inserted the same key/value, refcount and cleanup our thread data
profile = (UStringPrepProfile*) (uhash_get(SHARED_DATA_HASHTABLE,&stackKey));
if(profile != NULL) {
profile->refCount = 1;
uhash_put(SHARED_DATA_HASHTABLE, key.orphan(), profile, status);
}
- umtx_unlock(&usprepMutex);
+ umtx_unlock(usprepMutex());
}
return profile;
return;
}
- umtx_lock(&usprepMutex);
+ umtx_lock(usprepMutex());
/* decrement the ref count*/
if(profile->refCount > 0){
profile->refCount--;
}
- umtx_unlock(&usprepMutex);
+ umtx_unlock(usprepMutex());
}
return(uprv_isNaN(d));
}
-static icu::UMutex ccLock = U_MUTEX_INITIALIZER;
+static icu::UMutex *ccLock() {
+ static icu::UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
U_CDECL_BEGIN
static UBool calendar_astro_cleanup(void) {
if(U_FAILURE(status)) {
return 0;
}
- umtx_lock(&ccLock);
+ umtx_lock(ccLock());
if(*cache == NULL) {
createCache(cache, status);
if(U_FAILURE(status)) {
- umtx_unlock(&ccLock);
+ umtx_unlock(ccLock());
return 0;
}
}
res = uhash_igeti((*cache)->fTable, key);
U_DEBUG_ASTRO_MSG(("%p: GET: [%d] == %d\n", (*cache)->fTable, key, res));
- umtx_unlock(&ccLock);
+ umtx_unlock(ccLock());
return res;
}
if(U_FAILURE(status)) {
return;
}
- umtx_lock(&ccLock);
+ umtx_lock(ccLock());
if(*cache == NULL) {
createCache(cache, status);
if(U_FAILURE(status)) {
- umtx_unlock(&ccLock);
+ umtx_unlock(ccLock());
return;
}
}
uhash_iputi((*cache)->fTable, key, value, &status);
U_DEBUG_ASTRO_MSG(("%p: PUT: [%d] := %d\n", (*cache)->fTable, key, value));
- umtx_unlock(&ccLock);
+ umtx_unlock(ccLock());
}
CalendarCache::CalendarCache(int32_t size, UErrorCode &status) {
// --- The cache --
-static icu::UMutex astroLock = U_MUTEX_INITIALIZER; // Protects access to gChineseCalendarAstro.
+static icu::UMutex *astroLock() { // Protects access to gChineseCalendarAstro.
+ static icu::UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
static icu::CalendarAstronomer *gChineseCalendarAstro = NULL;
// Lazy Creation & Access synchronized by class CalendarCache with a mutex.
// PST 1298 with a final result of Dec 14 10:31:59 PST 1299.
double ms = daysToMillis(Grego::fieldsToDay(gyear, UCAL_DECEMBER, 1));
- umtx_lock(&astroLock);
+ umtx_lock(astroLock());
if(gChineseCalendarAstro == NULL) {
gChineseCalendarAstro = new CalendarAstronomer();
ucln_i18n_registerCleanup(UCLN_I18N_CHINESE_CALENDAR, calendar_chinese_cleanup);
}
gChineseCalendarAstro->setTime(ms);
UDate solarLong = gChineseCalendarAstro->getSunTime(CalendarAstronomer::WINTER_SOLSTICE(), TRUE);
- umtx_unlock(&astroLock);
+ umtx_unlock(astroLock());
// Winter solstice is 270 degrees solar longitude aka Dongzhi
cacheValue = (int32_t)millisToDays(solarLong);
*/
int32_t ChineseCalendar::newMoonNear(double days, UBool after) const {
- umtx_lock(&astroLock);
+ umtx_lock(astroLock());
if(gChineseCalendarAstro == NULL) {
gChineseCalendarAstro = new CalendarAstronomer();
ucln_i18n_registerCleanup(UCLN_I18N_CHINESE_CALENDAR, calendar_chinese_cleanup);
}
gChineseCalendarAstro->setTime(daysToMillis(days));
UDate newMoon = gChineseCalendarAstro->getMoonTime(CalendarAstronomer::NEW_MOON(), after);
- umtx_unlock(&astroLock);
+ umtx_unlock(astroLock());
return (int32_t) millisToDays(newMoon);
}
*/
int32_t ChineseCalendar::majorSolarTerm(int32_t days) const {
- umtx_lock(&astroLock);
+ umtx_lock(astroLock());
if(gChineseCalendarAstro == NULL) {
gChineseCalendarAstro = new CalendarAstronomer();
ucln_i18n_registerCleanup(UCLN_I18N_CHINESE_CALENDAR, calendar_chinese_cleanup);
}
gChineseCalendarAstro->setTime(daysToMillis(days));
UDate solarLongitude = gChineseCalendarAstro->getSunLongitude();
- umtx_unlock(&astroLock);
+ umtx_unlock(astroLock());
// Compute (floor(solarLongitude / (pi/6)) + 2) % 12
int32_t term = ( ((int32_t)(6 * solarLongitude / CalendarAstronomer::PI)) + 2 ) % 12;
static const char gContextTransformsTag[]="contextTransforms";
-static UMutex LOCK = U_MUTEX_INITIALIZER;
-
/**
* Jitterbug 2974: MSVC has a bug whereby new X[0] behaves badly.
* Work around this.
DateFormatSymbols::getZoneStrings(int32_t& rowCount, int32_t& columnCount) const
{
const UnicodeString **result = NULL;
+ static UMutex LOCK = U_MUTEX_INITIALIZER;
umtx_lock(&LOCK);
if (fZoneStrings == NULL) {
// Mutex, protects access to fDateFormat, fFromCalendar and fToCalendar.
// Needed because these data members are modified by const methods of DateIntervalFormat.
-static UMutex gFormatterMutex = U_MUTEX_INITIALIZER;
+static UMutex *gFormatterMutex() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
DateIntervalFormat* U_EXPORT2
DateIntervalFormat::createInstance(const UnicodeString& skeleton,
delete fTimePattern;
delete fDateTimeFormat;
{
- Mutex lock(&gFormatterMutex);
+ Mutex lock(gFormatterMutex());
if ( itvfmt.fDateFormat ) {
fDateFormat = (SimpleDateFormat*)itvfmt.fDateFormat->clone();
} else {
if ((fInfo != fmt->fInfo) && (fInfo == NULL || fmt->fInfo == NULL)) {return FALSE;}
if (fInfo && fmt->fInfo && (*fInfo != *fmt->fInfo )) {return FALSE;}
{
- Mutex lock(&gFormatterMutex);
+ Mutex lock(gFormatterMutex());
if (fDateFormat != fmt->fDateFormat && (fDateFormat == NULL || fmt->fDateFormat == NULL)) {return FALSE;}
if (fDateFormat && fmt->fDateFormat && (*fDateFormat != *fmt->fDateFormat)) {return FALSE;}
}
handler.setAcceptFirstOnly(TRUE);
int8_t ignore;
- Mutex lock(&gFormatterMutex);
+ Mutex lock(gFormatterMutex());
return formatIntervalImpl(*dtInterval, appendTo, ignore, handler, status);
}
auto handler = result->getHandler(status);
handler.setCategory(UFIELD_CATEGORY_DATE);
{
- Mutex lock(&gFormatterMutex);
+ Mutex lock(gFormatterMutex());
formatIntervalImpl(dtInterval, string, firstIndex, handler, status);
}
handler.getError(status);
handler.setAcceptFirstOnly(TRUE);
int8_t ignore;
- Mutex lock(&gFormatterMutex);
+ Mutex lock(gFormatterMutex());
return formatImpl(fromCalendar, toCalendar, appendTo, ignore, handler, status);
}
auto handler = result->getHandler(status);
handler.setCategory(UFIELD_CATEGORY_DATE);
{
- Mutex lock(&gFormatterMutex);
+ Mutex lock(gFormatterMutex());
formatImpl(fromCalendar, toCalendar, string, firstIndex, handler, status);
}
handler.getError(status);
DateIntervalFormat::getTimeZone() const
{
if (fDateFormat != NULL) {
- Mutex lock(&gFormatterMutex);
+ Mutex lock(gFormatterMutex());
return fDateFormat->getTimeZone();
}
// If fDateFormat is NULL (unexpected), create default timezone.
#include "uhash.h"
static UHashtable* gGenderInfoCache = NULL;
-static icu::UMutex gGenderMetaLock = U_MUTEX_INITIALIZER;
+
static const char* gNeutralStr = "neutral";
static const char* gMailTaintsStr = "maleTaints";
static const char* gMixedNeutralStr = "mixedNeutral";
return NULL;
}
+ static UMutex gGenderMetaLock = U_MUTEX_INITIALIZER;
const GenderInfo* result = NULL;
const char* key = locale.getName();
{
// --- The cache --
// cache of months
-static icu::UMutex astroLock = U_MUTEX_INITIALIZER; // pod bay door lock
static icu::CalendarCache *gMonthCache = NULL;
static icu::CalendarAstronomer *gIslamicCalendarAstro = NULL;
{
double age = 0;
+ static UMutex astroLock = U_MUTEX_INITIALIZER; // pod bay door lock
umtx_lock(&astroLock);
if(gIslamicCalendarAstro == NULL) {
gIslamicCalendarAstro = new CalendarAstronomer();
static Hashtable* listPatternHash = nullptr;
-static UMutex listFormatterMutex = U_MUTEX_INITIALIZER;
static const char STANDARD_STYLE[] = "standard";
U_CDECL_BEGIN
keyBuffer.append(':', errorCode).append(style, errorCode);
UnicodeString key(keyBuffer.data(), -1, US_INV);
ListFormatInternal* result = nullptr;
+ static UMutex listFormatterMutex = U_MUTEX_INITIALIZER;
{
Mutex m(&listFormatterMutex);
if (listPatternHash == nullptr) {
// Static hashtable cache of NumberingSystem objects used by NumberFormat
static UHashtable * NumberingSystem_cache = NULL;
-static icu::UMutex nscacheMutex = U_MUTEX_INITIALIZER;
static icu::UInitOnce gNSCacheInitOnce = U_INITONCE_INITIALIZER;
#if !UCONFIG_NO_SERVICE
// TODO: Bad hash key usage, see ticket #8504.
int32_t hashKey = desiredLocale.hashCode();
+ static icu::UMutex nscacheMutex = U_MUTEX_INITIALIZER;
Mutex lock(&nscacheMutex);
ns = (NumberingSystem *)uhash_iget(NumberingSystem_cache, hashKey);
if (ns == NULL) {
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(RuleBasedTransliterator)
-static UMutex transliteratorDataMutex = U_MUTEX_INITIALIZER;
static Replaceable *gLockedText = NULL;
void RuleBasedTransliterator::_construct(const UnicodeString& rules,
// Shared RBT data protected by transliteratorDataMutex.
//
// TODO(andy): Need a better scheme for handling this.
+
+ static UMutex transliteratorDataMutex = U_MUTEX_INITIALIZER;
UBool needToLock;
{
Mutex m;
fUpToDate = FALSE;
}
-static UMutex gLock = U_MUTEX_INITIALIZER;
void
RuleBasedTimeZone::completeConst(UErrorCode& status) const {
+ static UMutex gLock = U_MUTEX_INITIALIZER;
if (U_FAILURE(status)) {
return;
}
// Copied from uscript_props.cpp
-static icu::UMutex gBrkIterMutex = U_MUTEX_INITIALIZER;
-
U_NAMESPACE_BEGIN
// RelativeDateTimeFormatter specific data for a single locale
// Must guarantee that one thread at a time accesses the shared break
// iterator.
+ static icu::UMutex gBrkIterMutex = U_MUTEX_INITIALIZER;
Mutex lock(&gBrkIterMutex);
str.toTitle(
fOptBreakIterator->get(),
* allocate it in the constructors. This would be a more intrusive change, but doable
* if performance turns out to be an issue.
*/
-static UMutex gLock = U_MUTEX_INITIALIZER;
void
SimpleTimeZone::checkTransitionRules(UErrorCode& status) const {
if (U_FAILURE(status)) {
return;
}
+ static UMutex gLock = U_MUTEX_INITIALIZER;
umtx_lock(&gLock);
if (!transitionRulesInitialized) {
SimpleTimeZone *ncThis = const_cast<SimpleTimeZone*>(this);
static const int32_t HEBREW_CAL_CUR_MILLENIUM_START_YEAR = 5000;
static const int32_t HEBREW_CAL_CUR_MILLENIUM_END_YEAR = 6000;
-static UMutex LOCK = U_MUTEX_INITIALIZER;
+static UMutex *LOCK() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(SimpleDateFormat)
if ( fDateOverride.isBogus() && fTimeOverride.isBogus() ) {
return;
}
- umtx_lock(&LOCK);
+ umtx_lock(LOCK());
if (fSharedNumberFormatters == NULL) {
fSharedNumberFormatters = allocSharedNumberFormatters();
if (fSharedNumberFormatters == NULL) {
status = U_MEMORY_ALLOCATION_ERROR;
}
}
- umtx_unlock(&LOCK);
+ umtx_unlock(LOCK());
if (U_FAILURE(status)) {
return;
TimeZoneFormat *
SimpleDateFormat::tzFormat(UErrorCode &status) const {
if (fTimeZoneFormat == NULL) {
- umtx_lock(&LOCK);
+ umtx_lock(LOCK());
{
if (fTimeZoneFormat == NULL) {
TimeZoneFormat *tzfmt = TimeZoneFormat::createInstance(fLocale, status);
const_cast<SimpleDateFormat *>(this)->fTimeZoneFormat = tzfmt;
}
}
- umtx_unlock(&LOCK);
+ umtx_unlock(LOCK());
}
return fTimeZoneFormat;
}
/**
* The mutex controlling access to registry object.
*/
-static icu::UMutex registryMutex = U_MUTEX_INITIALIZER;
+static icu::UMutex *registryMutex() {
+ static icu::UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
/**
* System transliterator registry; non-null when initialized.
TransliteratorAlias* alias = 0;
Transliterator* t = 0;
- umtx_lock(®istryMutex);
+ umtx_lock(registryMutex());
if (HAVE_REGISTRY(ec)) {
t = registry->get(id, alias, ec);
}
- umtx_unlock(®istryMutex);
+ umtx_unlock(registryMutex());
if (U_FAILURE(ec)) {
delete t;
alias = 0;
// Step 2. reget
- umtx_lock(®istryMutex);
+ umtx_lock(registryMutex());
if (HAVE_REGISTRY(ec)) {
t = registry->reget(id, parser, alias, ec);
}
- umtx_unlock(®istryMutex);
+ umtx_unlock(registryMutex());
// Step 3. Loop back around!
} else {
void U_EXPORT2 Transliterator::registerFactory(const UnicodeString& id,
Transliterator::Factory factory,
Transliterator::Token context) {
- Mutex lock(®istryMutex);
+ Mutex lock(registryMutex());
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
_registerFactory(id, factory, context);
* @see #unregister
*/
void U_EXPORT2 Transliterator::registerInstance(Transliterator* adoptedPrototype) {
- Mutex lock(®istryMutex);
+ Mutex lock(registryMutex());
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
_registerInstance(adoptedPrototype);
void U_EXPORT2 Transliterator::registerAlias(const UnicodeString& aliasID,
const UnicodeString& realID) {
- Mutex lock(®istryMutex);
+ Mutex lock(registryMutex());
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
_registerAlias(aliasID, realID);
*/
void U_EXPORT2 Transliterator::unregister(const UnicodeString& ID) {
- Mutex lock(®istryMutex);
+ Mutex lock(registryMutex());
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
registry->remove(ID);
*/
int32_t U_EXPORT2 Transliterator::countAvailableIDs(void) {
int32_t retVal = 0;
- Mutex lock(®istryMutex);
+ Mutex lock(registryMutex());
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
retVal = registry->countAvailableIDs();
*/
const UnicodeString& U_EXPORT2 Transliterator::getAvailableID(int32_t index) {
const UnicodeString* result = NULL;
- umtx_lock(®istryMutex);
+ umtx_lock(registryMutex());
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
result = ®istry->getAvailableID(index);
}
- umtx_unlock(®istryMutex);
+ umtx_unlock(registryMutex());
U_ASSERT(result != NULL); // fail if no registry
return *result;
}
StringEnumeration* U_EXPORT2 Transliterator::getAvailableIDs(UErrorCode& ec) {
if (U_FAILURE(ec)) return NULL;
StringEnumeration* result = NULL;
- umtx_lock(®istryMutex);
+ umtx_lock(registryMutex());
if (HAVE_REGISTRY(ec)) {
result = registry->getAvailableIDs();
}
- umtx_unlock(®istryMutex);
+ umtx_unlock(registryMutex());
if (result == NULL) {
ec = U_INTERNAL_TRANSLITERATOR_ERROR;
}
}
int32_t U_EXPORT2 Transliterator::countAvailableSources(void) {
- Mutex lock(®istryMutex);
+ Mutex lock(registryMutex());
UErrorCode ec = U_ZERO_ERROR;
return HAVE_REGISTRY(ec) ? _countAvailableSources() : 0;
}
UnicodeString& U_EXPORT2 Transliterator::getAvailableSource(int32_t index,
UnicodeString& result) {
- Mutex lock(®istryMutex);
+ Mutex lock(registryMutex());
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
_getAvailableSource(index, result);
}
int32_t U_EXPORT2 Transliterator::countAvailableTargets(const UnicodeString& source) {
- Mutex lock(®istryMutex);
+ Mutex lock(registryMutex());
UErrorCode ec = U_ZERO_ERROR;
return HAVE_REGISTRY(ec) ? _countAvailableTargets(source) : 0;
}
UnicodeString& U_EXPORT2 Transliterator::getAvailableTarget(int32_t index,
const UnicodeString& source,
UnicodeString& result) {
- Mutex lock(®istryMutex);
+ Mutex lock(registryMutex());
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
_getAvailableTarget(index, source, result);
int32_t U_EXPORT2 Transliterator::countAvailableVariants(const UnicodeString& source,
const UnicodeString& target) {
- Mutex lock(®istryMutex);
+ Mutex lock(registryMutex());
UErrorCode ec = U_ZERO_ERROR;
return HAVE_REGISTRY(ec) ? _countAvailableVariants(source, target) : 0;
}
const UnicodeString& source,
const UnicodeString& target,
UnicodeString& result) {
- Mutex lock(®istryMutex);
+ Mutex lock(registryMutex());
UErrorCode ec = U_ZERO_ERROR;
if (HAVE_REGISTRY(ec)) {
_getAvailableVariant(index, source, target, result);
/**
* The mutex controlling access to SPECIAL_INVERSES
*/
-static UMutex LOCK = U_MUTEX_INITIALIZER;
+static UMutex *LOCK() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
TransliteratorIDParser::Specs::Specs(const UnicodeString& s, const UnicodeString& t,
const UnicodeString& v, UBool sawS,
bidirectional = FALSE;
}
- Mutex lock(&LOCK);
+ Mutex lock(LOCK());
UnicodeString *tempus = new UnicodeString(inverseTarget); // Used for null pointer check before usage.
if (tempus == NULL) {
UnicodeString* inverseTarget;
- umtx_lock(&LOCK);
+ umtx_lock(LOCK());
inverseTarget = (UnicodeString*) SPECIAL_INVERSES->get(specs.target);
- umtx_unlock(&LOCK);
+ umtx_unlock(LOCK());
if (inverseTarget != NULL) {
// If the original ID contained "Any-" then make the
static TextTrieMap *gShortZoneIdTrie = NULL;
static icu::UInitOnce gShortZoneIdTrieInitOnce = U_INITONCE_INITIALIZER;
-static UMutex gLock = U_MUTEX_INITIALIZER;
+static UMutex *gLock() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
U_CDECL_BEGIN
/**
return NULL;
}
- umtx_lock(&gLock);
+ umtx_lock(gLock());
if (fTimeZoneGenericNames == NULL) {
TimeZoneFormat *nonConstThis = const_cast<TimeZoneFormat *>(this);
nonConstThis->fTimeZoneGenericNames = TimeZoneGenericNames::createInstance(fLocale, status);
}
- umtx_unlock(&gLock);
+ umtx_unlock(gLock());
return fTimeZoneGenericNames;
}
return NULL;
}
- umtx_lock(&gLock);
+ umtx_lock(gLock());
if (fTZDBTimeZoneNames == NULL) {
TZDBTimeZoneNames *tzdbNames = new TZDBTimeZoneNames(fLocale);
if (tzdbNames == NULL) {
nonConstThis->fTZDBTimeZoneNames = tzdbNames;
}
}
- umtx_unlock(&gLock);
+ umtx_unlock(gLock());
return fTZDBTimeZoneNames;
}
return results;
}
-static UMutex gLock = U_MUTEX_INITIALIZER;
+static UMutex *gLock() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
class TZGNCore : public UMemory {
public:
const UChar *locname = NULL;
TZGNCore *nonConstThis = const_cast<TZGNCore *>(this);
- umtx_lock(&gLock);
+ umtx_lock(gLock());
{
locname = nonConstThis->getGenericLocationName(tzCanonicalID);
}
- umtx_unlock(&gLock);
+ umtx_unlock(gLock());
if (locname == NULL) {
name.setToBogus();
const UChar *uplname = NULL;
TZGNCore *nonConstThis = const_cast<TZGNCore *>(this);
- umtx_lock(&gLock);
+ umtx_lock(gLock());
{
uplname = nonConstThis->getPartialLocationName(tzCanonicalID, mzID, isLong, mzDisplayName);
}
- umtx_unlock(&gLock);
+ umtx_unlock(gLock());
if (uplname == NULL) {
name.setToBogus();
TZGNCore *nonConstThis = const_cast<TZGNCore *>(this);
- umtx_lock(&gLock);
+ umtx_lock(gLock());
{
fGNamesTrie.search(text, start, (TextTrieMapSearchResultHandler *)&handler, status);
}
- umtx_unlock(&gLock);
+ umtx_unlock(gLock());
if (U_FAILURE(status)) {
return NULL;
// All names are not yet loaded into the local trie.
// Load all available names into the trie. This could be very heavy.
- umtx_lock(&gLock);
+ umtx_lock(gLock());
{
if (!fGNamesTrieFullyLoaded) {
StringEnumeration *tzIDs = TimeZone::createTimeZoneIDEnumeration(UCAL_ZONE_TYPE_CANONICAL, NULL, NULL, status);
}
}
}
- umtx_unlock(&gLock);
+ umtx_unlock(gLock());
if (U_FAILURE(status)) {
return NULL;
}
- umtx_lock(&gLock);
+ umtx_lock(gLock());
{
// now try it again
fGNamesTrie.search(text, start, (TextTrieMapSearchResultHandler *)&handler, status);
}
- umtx_unlock(&gLock);
+ umtx_unlock(gLock());
results = handler.getMatches(maxLen);
if (results != NULL && maxLen > 0) {
} TZGNCoreRef;
// TZGNCore object cache handling
-static UMutex gTZGNLock = U_MUTEX_INITIALIZER;
+static UMutex *gTZGNLock() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
static UHashtable *gTZGNCoreCache = NULL;
static UBool gTZGNCoreCacheInitialized = FALSE;
}
TimeZoneGenericNames::~TimeZoneGenericNames() {
- umtx_lock(&gTZGNLock);
+ umtx_lock(gTZGNLock());
{
U_ASSERT(fRef->refCount > 0);
// Just decrement the reference count
fRef->refCount--;
}
- umtx_unlock(&gTZGNLock);
+ umtx_unlock(gTZGNLock());
}
TimeZoneGenericNames*
TZGNCoreRef *cacheEntry = NULL;
{
- Mutex lock(&gTZGNLock);
+ Mutex lock(gTZGNLock());
if (!gTZGNCoreCacheInitialized) {
// Create empty hashtable
TimeZoneGenericNames::clone() const {
TimeZoneGenericNames* other = new TimeZoneGenericNames();
if (other) {
- umtx_lock(&gTZGNLock);
+ umtx_lock(gTZGNLock());
{
// Just increments the reference count
fRef->refCount++;
other->fRef = fRef;
}
- umtx_unlock(&gTZGNLock);
+ umtx_unlock(gTZGNLock());
}
return other;
}
U_NAMESPACE_BEGIN
// TimeZoneNames object cache handling
-static UMutex gTimeZoneNamesLock = U_MUTEX_INITIALIZER;
+static UMutex *gTimeZoneNamesLock() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
static UHashtable *gTimeZoneNamesCache = NULL;
static UBool gTimeZoneNamesCacheInitialized = FALSE;
}
TimeZoneNamesDelegate::TimeZoneNamesDelegate(const Locale& locale, UErrorCode& status) {
- Mutex lock(&gTimeZoneNamesLock);
+ Mutex lock(gTimeZoneNamesLock());
if (!gTimeZoneNamesCacheInitialized) {
// Create empty hashtable if it is not already initialized.
gTimeZoneNamesCache = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &status);
}
TimeZoneNamesDelegate::~TimeZoneNamesDelegate() {
- umtx_lock(&gTimeZoneNamesLock);
+ umtx_lock(gTimeZoneNamesLock());
{
if (fTZnamesCacheEntry) {
U_ASSERT(fTZnamesCacheEntry->refCount > 0);
fTZnamesCacheEntry->refCount--;
}
}
- umtx_unlock(&gTimeZoneNamesLock);
+ umtx_unlock(gTimeZoneNamesLock());
}
UBool
TimeZoneNamesDelegate::clone() const {
TimeZoneNamesDelegate* other = new TimeZoneNamesDelegate();
if (other != NULL) {
- umtx_lock(&gTimeZoneNamesLock);
+ umtx_lock(gTimeZoneNamesLock());
{
// Just increment the reference count
fTZnamesCacheEntry->refCount++;
other->fTZnamesCacheEntry = fTZnamesCacheEntry;
}
- umtx_unlock(&gTimeZoneNamesLock);
+ umtx_unlock(gTimeZoneNamesLock());
}
return other;
}
static const char* TZDBNAMES_KEYS[] = {"ss", "sd"};
static const int32_t TZDBNAMES_KEYS_SIZE = UPRV_LENGTHOF(TZDBNAMES_KEYS);
-static UMutex gTZDBNamesMapLock = U_MUTEX_INITIALIZER;
-static UMutex gDataMutex = U_MUTEX_INITIALIZER;
+static UMutex *gDataMutex() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
static UHashtable* gTZDBNamesMap = NULL;
static icu::UInitOnce gTZDBNamesMapInitOnce = U_INITONCE_INITIALIZER;
return NULL;
}
-// Mutex for protecting the lazy creation of the Trie node structure on the first call to search().
-static UMutex TextTrieMutex = U_MUTEX_INITIALIZER;
// buildTrie() - The Trie node structure is needed. Create it from the data that was
// saved at the time the ZoneStringFormatter was created. The Trie is only
// the ICU atomic safe functions for assigning and testing.
// Don't test the pointer fLazyContents.
// 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 = U_MUTEX_INITIALIZER;
+
Mutex lock(&TextTrieMutex);
if (fLazyContents != NULL) {
TextTrieMap *nonConstThis = const_cast<TextTrieMap *>(this);
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
U_ASSERT(status == U_ZERO_ERROR); // already checked length above
mzIDKey[mzID.length()] = 0;
+ static UMutex gTZDBNamesMapLock = U_MUTEX_INITIALIZER;
umtx_lock(&gTZDBNamesMapLock);
{
void *cacheVal = uhash_get(gTZDBNamesMap, mzIDKey);
#include "olsontz.h"
#include "uinvchar.h"
-static icu::UMutex gZoneMetaLock = U_MUTEX_INITIALIZER;
+static icu::UMutex *gZoneMetaLock() {
+ static icu::UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
// CLDR Canonical ID mapping table
static UHashtable *gCanonicalIDCache = NULL;
}
// Check if it was already cached
- umtx_lock(&gZoneMetaLock);
+ umtx_lock(gZoneMetaLock());
{
canonicalID = (const UChar *)uhash_get(gCanonicalIDCache, utzid);
}
- umtx_unlock(&gZoneMetaLock);
+ umtx_unlock(gZoneMetaLock());
if (canonicalID != NULL) {
return canonicalID;
U_ASSERT(canonicalID != NULL); // canocanilD must be non-NULL here
// Put the resolved canonical ID to the cache
- umtx_lock(&gZoneMetaLock);
+ umtx_lock(gZoneMetaLock());
{
const UChar* idInCache = (const UChar *)uhash_get(gCanonicalIDCache, utzid);
if (idInCache == NULL) {
}
}
}
- umtx_unlock(&gZoneMetaLock);
+ umtx_unlock(gZoneMetaLock());
}
return canonicalID;
// Check if it was already cached
UBool cached = FALSE;
UBool singleZone = FALSE;
- umtx_lock(&gZoneMetaLock);
+ umtx_lock(gZoneMetaLock());
{
singleZone = cached = gSingleZoneCountries->contains((void*)region);
if (!cached) {
cached = gMultiZonesCountries->contains((void*)region);
}
}
- umtx_unlock(&gZoneMetaLock);
+ umtx_unlock(gZoneMetaLock());
if (!cached) {
// We need to go through all zones associated with the region.
delete ids;
// Cache the result
- umtx_lock(&gZoneMetaLock);
+ umtx_lock(gZoneMetaLock());
{
UErrorCode ec = U_ZERO_ERROR;
if (singleZone) {
}
}
}
- umtx_unlock(&gZoneMetaLock);
+ umtx_unlock(gZoneMetaLock());
}
if (singleZone) {
// get the mapping from cache
const UVector *result = NULL;
- umtx_lock(&gZoneMetaLock);
+ umtx_lock(gZoneMetaLock());
{
result = (UVector*) uhash_get(gOlsonToMeta, tzidUChars);
}
- umtx_unlock(&gZoneMetaLock);
+ umtx_unlock(gZoneMetaLock());
if (result != NULL) {
return result;
}
// put the new one into the cache
- umtx_lock(&gZoneMetaLock);
+ umtx_lock(gZoneMetaLock());
{
// make sure it's already created
result = (UVector*) uhash_get(gOlsonToMeta, tzidUChars);
delete tmpResult;
}
}
- umtx_unlock(&gZoneMetaLock);
+ umtx_unlock(gZoneMetaLock());
return result;
}
}
U_CDECL_END
-static icu::UMutex gLock = U_MUTEX_INITIALIZER;
static inline UNumberFormat * copyInvariantFormatter(ULocaleBundle *result, UNumberFormatStyle style) {
U_NAMESPACE_USE
+ static UMutex gLock = U_MUTEX_INITIALIZER;
Mutex lock(&gLock);
if (result->fNumberFormat[style-1] == NULL) {
if (gPosixNumberFormat[style-1] == NULL) {
}
}
-static UMutex messageMutex = U_MUTEX_INITIALIZER;
void IntlTest::LL_message( UnicodeString message, UBool newline )
{
// All error messages generated by tests funnel through here.
// Multithreaded tests can concurrently generate errors, requiring synchronization
// to keep each message together.
+ static UMutex messageMutex = U_MUTEX_INITIALIZER;
Mutex lock(&messageMutex);
// string that starts with a LineFeed character and continues
// platform's mutex support is at least superficially there.
//
//----------------------------------------------------------------------
-static UMutex gTestMutexA = U_MUTEX_INITIALIZER;
-static UConditionVar gThreadsCountChanged = U_CONDITION_INITIALIZER;
+static UMutex *gTestMutexA() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
+static UConditionVar *gThreadsCountChanged() {
+ static UConditionVar cv = U_CONDITION_INITIALIZER;
+ return &cv;
+}
static int gThreadsStarted = 0;
static int gThreadsInMiddle = 0;
// This is the code that each of the spawned threads runs.
// All threads move together throught the started - middle - done sequence together,
// waiting for all other threads to reach each point before advancing.
- umtx_lock(&gTestMutexA);
+ umtx_lock(gTestMutexA());
gThreadsStarted += 1;
- umtx_condBroadcast(&gThreadsCountChanged);
+ umtx_condBroadcast(gThreadsCountChanged());
while (gThreadsStarted < TESTMUTEX_THREAD_COUNT) {
if (gThreadsInMiddle != 0) {
IntlTest::gTest->errln(
"%s:%d gThreadsInMiddle = %d. Expected 0.", __FILE__, __LINE__, gThreadsInMiddle);
return;
}
- umtx_condWait(&gThreadsCountChanged, &gTestMutexA);
+ umtx_condWait(gThreadsCountChanged(), gTestMutexA());
}
gThreadsInMiddle += 1;
- umtx_condBroadcast(&gThreadsCountChanged);
+ umtx_condBroadcast(gThreadsCountChanged());
while (gThreadsInMiddle < TESTMUTEX_THREAD_COUNT) {
if (gThreadsDone != 0) {
IntlTest::gTest->errln(
"%s:%d gThreadsDone = %d. Expected 0.", __FILE__, __LINE__, gThreadsDone);
return;
}
- umtx_condWait(&gThreadsCountChanged, &gTestMutexA);
+ umtx_condWait(gThreadsCountChanged(), gTestMutexA());
}
gThreadsDone += 1;
- umtx_condBroadcast(&gThreadsCountChanged);
+ umtx_condBroadcast(gThreadsCountChanged());
while (gThreadsDone < TESTMUTEX_THREAD_COUNT) {
- umtx_condWait(&gThreadsCountChanged, &gTestMutexA);
+ umtx_condWait(gThreadsCountChanged(), gTestMutexA());
}
- umtx_unlock(&gTestMutexA);
+ umtx_unlock(gTestMutexA());
}
};
gThreadsDone = 0;
int32_t i = 0;
TestMutexThread threads[TESTMUTEX_THREAD_COUNT];
- umtx_lock(&gTestMutexA);
+ umtx_lock(gTestMutexA());
for (i=0; i<TESTMUTEX_THREAD_COUNT; i++) {
if (threads[i].start() != 0) {
errln("%s:%d Error starting thread %d", __FILE__, __LINE__, i);
errln("%s:%d gThreadsDone=%d. Expected 0.", __FILE__, __LINE__, gThreadsStarted);
return;
}
- umtx_condWait(&gThreadsCountChanged, &gTestMutexA);
+ umtx_condWait(gThreadsCountChanged(), gTestMutexA());
}
while (gThreadsDone < TESTMUTEX_THREAD_COUNT) {
- umtx_condWait(&gThreadsCountChanged, &gTestMutexA);
+ umtx_condWait(gThreadsCountChanged(), gTestMutexA());
}
- umtx_unlock(&gTestMutexA);
+ umtx_unlock(gTestMutexA());
for (i=0; i<TESTMUTEX_THREAD_COUNT; i++) {
threads[i].join();
bool fFinished;
};
-static UMutex gCTMutex = U_MUTEX_INITIALIZER;
-static UConditionVar gCTConditionVar = U_CONDITION_INITIALIZER;
+static UMutex *gCTMutex() {
+ static UMutex m = U_MUTEX_INITIALIZER;
+ return &m;
+}
+static UConditionVar *gCTConditionVar() {
+ static UConditionVar cv = U_CONDITION_INITIALIZER;
+ return &cv;
+}
int gConditionTestOne = 1; // Value one. Non-const, extern linkage to inhibit
// compiler assuming a known value.
int gStartedThreads;
// Worker thread function.
void CondThread::run() {
- umtx_lock(&gCTMutex);
+ umtx_lock(gCTMutex());
gStartedThreads += gConditionTestOne;
- umtx_condBroadcast(&gCTConditionVar);
+ umtx_condBroadcast(gCTConditionVar());
while (gStartedThreads < NUMTHREADS) {
if (gFinishedThreads != 0) {
IntlTest::gTest->errln("File %s, Line %d: Error, gStartedThreads = %d, gFinishedThreads = %d",
__FILE__, __LINE__, gStartedThreads, gFinishedThreads);
}
- umtx_condWait(&gCTConditionVar, &gCTMutex);
+ umtx_condWait(gCTConditionVar(), gCTMutex());
}
gFinishedThreads += gConditionTestOne;
fFinished = true;
- umtx_condBroadcast(&gCTConditionVar);
+ umtx_condBroadcast(gCTConditionVar());
while (gFinishedThreads < NUMTHREADS) {
- umtx_condWait(&gCTConditionVar, &gCTMutex);
+ umtx_condWait(gCTConditionVar(), gCTMutex());
}
- umtx_unlock(&gCTMutex);
+ umtx_unlock(gCTMutex());
}
void MultithreadTest::TestConditionVariables() {
gFinishedThreads = 0;
int i;
- umtx_lock(&gCTMutex);
+ umtx_lock(gCTMutex());
CondThread *threads[NUMTHREADS];
for (i=0; i<NUMTHREADS; ++i) {
threads[i] = new CondThread;
}
while (gStartedThreads < NUMTHREADS) {
- umtx_condWait(&gCTConditionVar, &gCTMutex);
+ umtx_condWait(gCTConditionVar(), gCTMutex());
}
while (gFinishedThreads < NUMTHREADS) {
- umtx_condWait(&gCTConditionVar, &gCTMutex);
+ umtx_condWait(gCTConditionVar(), gCTMutex());
}
- umtx_unlock(&gCTMutex);
+ umtx_unlock(gCTMutex());
for (i=0; i<NUMTHREADS; ++i) {
assertTrue(WHERE, threads[i]->fFinished);
return result;
}
- umtx_lock(&gCTMutex);
+ umtx_lock(gCTMutex());
bool firstObject = (gObjectsCreated == 0);
if (firstObject) {
// Force the first object creation that comes through to wait
// early, to keep subsequent threads from entering this path.
gObjectsCreated = 1;
while (gObjectsCreated < 3) {
- umtx_condWait(&gCTConditionVar, &gCTMutex);
+ umtx_condWait(gCTConditionVar(), gCTMutex());
}
}
- umtx_unlock(&gCTMutex);
+ umtx_unlock(gCTMutex());
const UCTMultiThreadItem *result =
new UCTMultiThreadItem(fLoc.getLanguage());
// Log that we created an object. The first object was already counted,
// don't do it again.
- umtx_lock(&gCTMutex);
+ umtx_lock(gCTMutex());
if (!firstObject) {
gObjectsCreated += 1;
}
- umtx_condBroadcast(&gCTConditionVar);
- umtx_unlock(&gCTMutex);
+ umtx_condBroadcast(gCTConditionVar());
+ umtx_unlock(gCTMutex());
return result;
}