ICU-3039 various thread safety cleanups
X-SVN-Rev: 14565
This commit is contained in:
parent
cdbbd81e4a
commit
e61e59075f
@ -1828,8 +1828,9 @@ The leftmost codepage (.xxx) wins.
|
||||
|
||||
}
|
||||
|
||||
U_CAPI const char* U_EXPORT2
|
||||
uprv_getDefaultCodepage()
|
||||
|
||||
static const char*
|
||||
int_getDefaultCodepage()
|
||||
{
|
||||
#if defined(OS400)
|
||||
uint32_t ccsid = 37; /* Default to ibm-37 */
|
||||
@ -1945,6 +1946,21 @@ uprv_getDefaultCodepage()
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
U_CAPI const char* U_EXPORT2
|
||||
uprv_getDefaultCodepage()
|
||||
{
|
||||
static char const *name = NULL;
|
||||
umtx_lock(NULL);
|
||||
if (name == NULL) {
|
||||
name = int_getDefaultCodepage();
|
||||
}
|
||||
umtx_unlock(NULL);
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* invariant-character handling --------------------------------------------- */
|
||||
|
||||
/*
|
||||
|
@ -175,7 +175,6 @@ uprv_loadPropsData(UErrorCode *errorCode) {
|
||||
uprv_memcpy(&propsTrie, &trie, sizeof(trie));
|
||||
uprv_memcpy(&propsVectorsTrie, &trie2, sizeof(trie2));
|
||||
}
|
||||
umtx_unlock(NULL);
|
||||
|
||||
/* initialize some variables */
|
||||
uprv_memcpy(indexes, pData32, sizeof(indexes));
|
||||
@ -191,6 +190,7 @@ uprv_loadPropsData(UErrorCode *errorCode) {
|
||||
}
|
||||
|
||||
havePropsData=1;
|
||||
umtx_unlock(NULL);
|
||||
|
||||
/* if a different thread set it first, then close the extra data */
|
||||
if(data!=NULL) {
|
||||
|
@ -58,6 +58,9 @@ u_cleanup(void)
|
||||
ECleanupLibraryType libType;
|
||||
|
||||
UTRACE_ENTRY_OC(UTRACE_U_CLEANUP);
|
||||
umtx_lock(NULL); /* Force a memory barrier, so that we are sure to see */
|
||||
umtx_unlock(NULL); /* all state left around by any other threads. */
|
||||
|
||||
for (libType = UCLN_START+1; libType<UCLN_COMMON; libType++) {
|
||||
if (gCleanupFunctions[libType])
|
||||
{
|
||||
|
@ -1009,9 +1009,7 @@ ucnv_io_getDefaultConverterName() {
|
||||
UConverter *cnv = NULL;
|
||||
int32_t length = 0;
|
||||
|
||||
umtx_lock(NULL);
|
||||
name = uprv_getDefaultCodepage();
|
||||
umtx_unlock(NULL);
|
||||
|
||||
/* if the name is there, test it out and get the canonical name with options */
|
||||
if(name != NULL) {
|
||||
@ -1055,6 +1053,7 @@ ucnv_io_getDefaultConverterName() {
|
||||
|
||||
U_CFUNC void
|
||||
ucnv_io_setDefaultConverterName(const char *converterName) {
|
||||
umtx_lock(NULL);
|
||||
if(converterName==NULL) {
|
||||
/* reset to the default codepage */
|
||||
gDefaultConverterName=NULL;
|
||||
@ -1062,7 +1061,6 @@ ucnv_io_setDefaultConverterName(const char *converterName) {
|
||||
UErrorCode errorCode=U_ZERO_ERROR;
|
||||
const char *name=ucnv_io_getConverterName(converterName, &errorCode);
|
||||
|
||||
umtx_lock(NULL);
|
||||
|
||||
if(U_SUCCESS(errorCode) && name!=NULL) {
|
||||
gDefaultConverterName=name;
|
||||
@ -1077,8 +1075,8 @@ ucnv_io_setDefaultConverterName(const char *converterName) {
|
||||
}
|
||||
}
|
||||
|
||||
umtx_unlock(NULL);
|
||||
}
|
||||
umtx_unlock(NULL);
|
||||
}
|
||||
|
||||
/* alias table swapping ----------------------------------------------------- */
|
||||
|
@ -204,17 +204,30 @@ static void U_EXPORT2 U_CALLCONV DataCacheElement_deleter(void *pDCEl) {
|
||||
* Lazy create it if it doesn't yet exist.
|
||||
*/
|
||||
static UHashtable *udata_getHashTable() {
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
UBool cacheIsInitialized;
|
||||
UHashtable *tHT = NULL;
|
||||
|
||||
if (gCommonDataCache != NULL) {
|
||||
umtx_lock(NULL);
|
||||
cacheIsInitialized = (gCommonDataCache != NULL);
|
||||
umtx_unlock(NULL);
|
||||
|
||||
if (cacheIsInitialized) {
|
||||
return gCommonDataCache;
|
||||
}
|
||||
|
||||
tHT = uhash_open(uhash_hashChars, uhash_compareChars, &err);
|
||||
uhash_setValueDeleter(tHT, DataCacheElement_deleter);
|
||||
|
||||
umtx_lock(NULL);
|
||||
if (gCommonDataCache == NULL) {
|
||||
gCommonDataCache = uhash_open(uhash_hashChars, uhash_compareChars, &err);
|
||||
uhash_setValueDeleter(gCommonDataCache, DataCacheElement_deleter);
|
||||
gCommonDataCache = tHT;
|
||||
tHT = NULL;
|
||||
}
|
||||
umtx_unlock(NULL);
|
||||
if (tHT != NULL) {
|
||||
uhash_close(tHT);
|
||||
}
|
||||
|
||||
if (U_FAILURE(err)) {
|
||||
return NULL; /* TODO: handle this error better. */
|
||||
|
@ -325,7 +325,6 @@ loadNormData(UErrorCode &errorCode) {
|
||||
} else {
|
||||
p=(const int32_t *)udata_getMemory(normData);
|
||||
}
|
||||
umtx_unlock(NULL);
|
||||
|
||||
/* initialize some variables */
|
||||
extraData=(uint16_t *)((uint8_t *)(p+_NORM_INDEX_TOP)+indexes[_NORM_INDEX_TRIE_SIZE]);
|
||||
@ -338,6 +337,7 @@ loadNormData(UErrorCode &errorCode) {
|
||||
(indexes[_NORM_INDEX_FCD_TRIE_SIZE]+indexes[_NORM_INDEX_AUX_TRIE_SIZE])/2;
|
||||
}
|
||||
haveNormData=1;
|
||||
umtx_unlock(NULL);
|
||||
|
||||
/* if a different thread set it first, then close the extra data */
|
||||
if(data!=NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user