/**
*******************************************************************************
-* Copyright (C) 2001-2010, International Business Machines Corporation.
+* Copyright (C) 2001-2012, International Business Machines Corporation.
* All Rights Reserved.
*******************************************************************************
*/
******************************************************************
*/
+ICUServiceFactory::~ICUServiceFactory() {}
+
SimpleFactory::SimpleFactory(UObject* instanceToAdopt, const UnicodeString& id, UBool visible)
: _instance(instanceToAdopt), _id(id), _visible(visible)
{
******************************************************************
*/
+ServiceListener::~ServiceListener() {}
+
UOBJECT_DEFINE_RTTI_IMPLEMENTATION(ServiceListener)
/*
DNCache(const Locale& _locale)
: cache(), locale(_locale)
{
- // cache.setKeyDeleter(uhash_deleteUnicodeString);
+ // cache.setKeyDeleter(uprv_deleteUObject);
}
};
******************************************************************
*/
+static UMutex lock = U_MUTEX_INITIALIZER;
+
ICUService::ICUService()
: name()
-, lock(0)
, timestamp(0)
, factories(NULL)
, serviceCache(NULL)
, idCache(NULL)
, dnCache(NULL)
{
- umtx_init(&lock);
}
ICUService::ICUService(const UnicodeString& newName)
: name(newName)
-, lock(0)
, timestamp(0)
, factories(NULL)
, serviceCache(NULL)
, idCache(NULL)
, dnCache(NULL)
{
- umtx_init(&lock);
}
ICUService::~ICUService()
delete factories;
factories = NULL;
}
- umtx_destroy(&lock);
}
UObject*
// reentrantly even without knowing the thread.
class XMutex : public UMemory {
public:
- inline XMutex(UMTX *mutex, UBool reentering)
+ inline XMutex(UMutex *mutex, UBool reentering)
: fMutex(mutex)
, fActive(!reentering)
{
}
private:
- UMTX *fMutex;
+ UMutex *fMutex;
UBool fActive;
};
// 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(&ncthis->lock, factory != NULL);
+ XMutex mutex(&lock, factory != NULL);
if (serviceCache == NULL) {
ncthis->serviceCache = new Hashtable(status);
// fallback to the one that succeeded, we want to hit the
// cache the first time next goaround.
if (cacheDescriptorList._obj == NULL) {
- cacheDescriptorList._obj = new UVector(uhash_deleteUnicodeString, NULL, 5, status);
+ cacheDescriptorList._obj = new UVector(uprv_deleteUObject, NULL, 5, status);
if (U_FAILURE(status)) {
return NULL;
}
return result;
}
- ICUService * ncthis = (ICUService*)this; // cast away semantic const
{
- Mutex mutex(&ncthis->lock);
+ Mutex mutex(&lock);
const Hashtable* map = getVisibleIDMap(status);
if (map != NULL) {
ICUServiceKey* fallbackKey = createKey(matchID, status);
ICUService::getDisplayName(const UnicodeString& id, UnicodeString& result, const Locale& locale) const
{
{
- ICUService* ncthis = (ICUService*)this; // cast away semantic const
UErrorCode status = U_ZERO_ERROR;
- Mutex mutex(&ncthis->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(&ncthis->lock);
+ Mutex mutex(&lock);
if (dnCache != NULL && dnCache->locale != locale) {
delete dnCache;
if (dnCache == NULL) {
const Hashtable* m = getVisibleIDMap(status);
- if (m != NULL) {
- ncthis->dnCache = new DNCache(locale);
- if (dnCache == NULL) {
- status = U_MEMORY_ALLOCATION_ERROR;
- return result;
- }
+ if (U_FAILURE(status)) {
+ return result;
+ }
+ ncthis->dnCache = new DNCache(locale);
+ if (dnCache == NULL) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ return result;
+ }
- int32_t pos = -1;
- const UHashElement* entry = NULL;
- while ((entry = m->nextElement(pos)) != NULL) {
- const UnicodeString* id = (const UnicodeString*)entry->key.pointer;
- ICUServiceFactory* f = (ICUServiceFactory*)entry->value.pointer;
- UnicodeString dname;
- f->getDisplayName(*id, locale, dname);
- if (dname.isBogus()) {
- status = U_MEMORY_ALLOCATION_ERROR;
- } else {
- dnCache->cache.put(dname, (void*)id, status); // share pointer with visibleIDMap
- if (U_SUCCESS(status)) {
- continue;
- }
+ int32_t pos = -1;
+ const UHashElement* entry = NULL;
+ while ((entry = m->nextElement(pos)) != NULL) {
+ const UnicodeString* id = (const UnicodeString*)entry->key.pointer;
+ ICUServiceFactory* f = (ICUServiceFactory*)entry->value.pointer;
+ UnicodeString dname;
+ f->getDisplayName(*id, locale, dname);
+ if (dname.isBogus()) {
+ status = U_MEMORY_ALLOCATION_ERROR;
+ } else {
+ dnCache->cache.put(dname, (void*)id, status); // share pointer with visibleIDMap
+ if (U_SUCCESS(status)) {
+ continue;
}
- delete dnCache;
- ncthis->dnCache = NULL;
- return result;
}
+ delete dnCache;
+ ncthis->dnCache = NULL;
+ return result;
}
}
}