From 749f51d769e79683b8bcfe0bb20d8261dd41d2a0 Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Fri, 9 May 2003 21:33:17 +0000 Subject: [PATCH] ICU-2787 A lock doesn't need to happen when it's an algorithmic converter. X-SVN-Rev: 11874 --- icu4c/source/common/ucnv.c | 18 ++++++++++++++++-- icu4c/source/common/ucnv_bld.c | 9 +++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/icu4c/source/common/ucnv.c b/icu4c/source/common/ucnv.c index 21bb020f0d2..be7c686a478 100644 --- a/icu4c/source/common/ucnv.c +++ b/icu4c/source/common/ucnv.c @@ -289,7 +289,14 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U } /* increment refcount of shared data if needed */ - ucnv_incrementRefCount(cnv->sharedData); + /* + Checking whether it's an algorithic converter is okay + in multithreaded applications because the value never changes. + Don't check referenceCounter for any other value. + */ + if (cnv->sharedData->referenceCounter != ~0) { + ucnv_incrementRefCount(cnv->sharedData); + } if(localConverter==NULL || U_FAILURE(*status)) { return NULL; @@ -390,7 +397,14 @@ ucnv_close (UConverter * converter) } #endif - ucnv_unloadSharedDataIfReady(converter->sharedData); + /* + Checking whether it's an algorithic converter is okay + in multithreaded applications because the value never changes. + Don't check referenceCounter for any other value. + */ + if (converter->sharedData->referenceCounter != ~0) { + ucnv_unloadSharedDataIfReady(converter->sharedData); + } if(!converter->isCopyLocal){ UCNV_DEBUG_LOG("close:free", "", converter); diff --git a/icu4c/source/common/ucnv_bld.c b/icu4c/source/common/ucnv_bld.c index 3238dd5709a..16e87969f3b 100644 --- a/icu4c/source/common/ucnv_bld.c +++ b/icu4c/source/common/ucnv_bld.c @@ -656,11 +656,16 @@ ucnv_createConverter(UConverter *myUConverter, const char *converterName, UError if (U_FAILURE(*err)) { - umtx_lock(&cnvCacheMutex); + /* + Checking whether it's an algorithic converter is okay + in multithreaded applications because the value never changes. + Don't check referenceCounter for any other value. + */ if (mySharedConverterData->referenceCounter != ~0) { + umtx_lock(&cnvCacheMutex); --mySharedConverterData->referenceCounter; + umtx_unlock(&cnvCacheMutex); } - umtx_unlock(&cnvCacheMutex); return NULL; }