ICU-6479 thread safety in collation initialization

X-SVN-Rev: 24448
This commit is contained in:
Andy Heninger 2008-08-06 17:57:45 +00:00
parent 587e129139
commit 1de383df48
2 changed files with 8 additions and 3 deletions

View File

@ -907,7 +907,7 @@ static const UChar32
UCOL_MAX_INPUT = 0x220001; // 2 * Unicode range + 2
/**
* Precomputed by constructor
* Precomputed by initImplicitConstants()
*/
static int32_t
final3Multiplier = 0,
@ -1107,6 +1107,10 @@ static inline int32_t divideAndRoundUp(int a, int b) {
/**
* Set up to generate implicits.
* Maintenance Note: this function may end up being called more than once, due
* to threading races during initialization. Make sure that
* none of the Constants is ever transiently assigned an
* incorrect value.
* @param minPrimary
* @param maxPrimary
* @param minTrail final byte

View File

@ -113,6 +113,9 @@ ucol_initUCA(UErrorCode *status) {
if(U_SUCCESS(*status)){
UCollator *newUCA = ucol_initCollator((const UCATableHeader *)udata_getMemory(result), NULL, NULL, status);
if(U_SUCCESS(*status)){
// Initalize variables for implicit generation
uprv_uca_initImplicitConstants(status);
umtx_lock(NULL);
if(_staticUCA == NULL) {
UCA_DATA_MEM = result;
@ -127,8 +130,6 @@ ucol_initUCA(UErrorCode *status) {
ucol_close(newUCA);
udata_close(result);
}
// Initalize variables for implicit generation
uprv_uca_initImplicitConstants(status);
}else{
ucol_close(newUCA);
udata_close(result);