/*initializes some global variables */
static UHashtable *SHARED_DATA_HASHTABLE = NULL;
-static 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 = STATIC_NEW(icu::UMutex);
+ 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) {