OLD | NEW |
(Empty) | |
| 1 diff --git a/source/common/udata.cpp b/source/common/udata.cpp |
| 2 index e6d8a35..80bea06 100644 |
| 3 --- a/source/common/udata.cpp |
| 4 +++ b/source/common/udata.cpp |
| 5 @@ -1,7 +1,7 @@ |
| 6 /* |
| 7 ****************************************************************************** |
| 8 * |
| 9 -* Copyright (C) 1999-2014, International Business Machines |
| 10 +* Copyright (C) 1999-2015, International Business Machines |
| 11 * Corporation and others. All Rights Reserved. |
| 12 * |
| 13 ****************************************************************************** |
| 14 @@ -29,6 +29,7 @@ might have to #include some other header |
| 15 #include "charstr.h" |
| 16 #include "cmemory.h" |
| 17 #include "cstring.h" |
| 18 +#include "mutex.h" |
| 19 #include "putilimp.h" |
| 20 #include "uassert.h" |
| 21 #include "ucln_cmn.h" |
| 22 @@ -100,14 +101,15 @@ static UDataMemory *udata_findCachedData(const char *path)
; |
| 23 * that they really need, reducing the size of binaries that take advantage |
| 24 * of this. |
| 25 */ |
| 26 -static UDataMemory *gCommonICUDataArray[10] = { NULL }; |
| 27 +static UDataMemory *gCommonICUDataArray[10] = { NULL }; // Access protected b
y icu global mutex. |
| 28 |
| 29 -static UBool gHaveTriedToLoadCommonData = FALSE; /* See extendICUData(). */ |
| 30 +static u_atomic_int32_t gHaveTriedToLoadCommonData = ATOMIC_INT32_T_INITIALIZER
(0); // See extendICUData(). |
| 31 |
| 32 static UHashtable *gCommonDataCache = NULL; /* Global hash table of opened IC
U data files. */ |
| 33 static icu::UInitOnce gCommonDataCacheInitOnce = U_INITONCE_INITIALIZER; |
| 34 |
| 35 -static UDataFileAccess gDataFileAccess = UDATA_DEFAULT_ACCESS; |
| 36 +static UDataFileAccess gDataFileAccess = UDATA_DEFAULT_ACCESS; // Access not
synchronized. |
| 37 + // Modifying i
s documented as thread-unsafe. |
| 38 |
| 39 static UBool U_CALLCONV |
| 40 udata_cleanup(void) |
| 41 @@ -124,7 +126,7 @@ udata_cleanup(void) |
| 42 udata_close(gCommonICUDataArray[i]); |
| 43 gCommonICUDataArray[i] = NULL; |
| 44 } |
| 45 - gHaveTriedToLoadCommonData = FALSE; |
| 46 + gHaveTriedToLoadCommonData = 0; |
| 47 |
| 48 return TRUE; /* Everything was cleaned up */ |
| 49 } |
| 50 @@ -139,14 +141,16 @@ findCommonICUDataByName(const char *inBasename) |
| 51 if (pData == NULL) |
| 52 return FALSE; |
| 53 |
| 54 - for (i = 0; i < UPRV_LENGTHOF(gCommonICUDataArray); ++i) { |
| 55 - if ((gCommonICUDataArray[i] != NULL) && (gCommonICUDataArray[i]->pHeade
r == pData->pHeader)) { |
| 56 - /* The data pointer is already in the array. */ |
| 57 - found = TRUE; |
| 58 - break; |
| 59 + { |
| 60 + Mutex lock; |
| 61 + for (i = 0; i < UPRV_LENGTHOF(gCommonICUDataArray); ++i) { |
| 62 + if ((gCommonICUDataArray[i] != NULL) && (gCommonICUDataArray[i]->pH
eader == pData->pHeader)) { |
| 63 + /* The data pointer is already in the array. */ |
| 64 + found = TRUE; |
| 65 + break; |
| 66 + } |
| 67 } |
| 68 } |
| 69 - |
| 70 return found; |
| 71 } |
| 72 |
| 73 @@ -663,7 +667,11 @@ openCommonData(const char *path, /* Path from Ope
nChoice? */ |
| 74 if(commonDataIndex >= UPRV_LENGTHOF(gCommonICUDataArray)) { |
| 75 return NULL; |
| 76 } |
| 77 - if(gCommonICUDataArray[commonDataIndex] == NULL) { |
| 78 + { |
| 79 + Mutex lock; |
| 80 + if(gCommonICUDataArray[commonDataIndex] != NULL) { |
| 81 + return gCommonICUDataArray[commonDataIndex]; |
| 82 + } |
| 83 int32_t i; |
| 84 for(i = 0; i < commonDataIndex; ++i) { |
| 85 if(gCommonICUDataArray[i]->pHeader == &U_ICUDATA_ENTRY_POINT.hd
r) { |
| 86 @@ -671,23 +679,26 @@ openCommonData(const char *path, /* Path from Op
enChoice? */ |
| 87 return NULL; |
| 88 } |
| 89 } |
| 90 + } |
| 91 |
| 92 - /* Add the linked-in data to the list. */ |
| 93 - /* |
| 94 - * This is where we would check and call weakly linked partial-data
-library |
| 95 - * access functions. |
| 96 - */ |
| 97 - /* |
| 98 - if (uprv_getICUData_collation) { |
| 99 - setCommonICUDataPointer(uprv_getICUData_collation(), FALSE, pEr
rorCode); |
| 100 - } |
| 101 - if (uprv_getICUData_conversion) { |
| 102 - setCommonICUDataPointer(uprv_getICUData_conversion(), FALSE, pE
rrorCode); |
| 103 - } |
| 104 - */ |
| 105 - setCommonICUDataPointer(&U_ICUDATA_ENTRY_POINT.hdr, FALSE, pErrorCo
de); |
| 106 + /* Add the linked-in data to the list. */ |
| 107 + /* |
| 108 + * This is where we would check and call weakly linked partial-data-lib
rary |
| 109 + * access functions. |
| 110 + */ |
| 111 + /* |
| 112 + if (uprv_getICUData_collation) { |
| 113 + setCommonICUDataPointer(uprv_getICUData_collation(), FALSE, pErrorC
ode); |
| 114 + } |
| 115 + if (uprv_getICUData_conversion) { |
| 116 + setCommonICUDataPointer(uprv_getICUData_conversion(), FALSE, pError
Code); |
| 117 + } |
| 118 + */ |
| 119 + setCommonICUDataPointer(&U_ICUDATA_ENTRY_POINT.hdr, FALSE, pErrorCode); |
| 120 + { |
| 121 + Mutex lock; |
| 122 + return gCommonICUDataArray[commonDataIndex]; |
| 123 } |
| 124 - return gCommonICUDataArray[commonDataIndex]; |
| 125 } |
| 126 |
| 127 |
| 128 @@ -795,7 +806,7 @@ static UBool extendICUData(UErrorCode *pErr) |
| 129 static UMutex extendICUDataMutex = U_MUTEX_INITIALIZER; |
| 130 umtx_lock(&extendICUDataMutex); |
| 131 #endif |
| 132 - if(!gHaveTriedToLoadCommonData) { |
| 133 + if(!umtx_loadAcquire(gHaveTriedToLoadCommonData)) { |
| 134 /* See if we can explicitly open a .dat file for the ICUData. */ |
| 135 pData = openCommonData( |
| 136 U_ICUDATA_NAME, /* "icudt20l" , for example.
*/ |
| 137 @@ -820,7 +831,7 @@ static UBool extendICUData(UErrorCode *pErr) |
| 138 pErr); /* setCommonICUData honors errors; N
OP if error set */ |
| 139 } |
| 140 |
| 141 - gHaveTriedToLoadCommonData = TRUE; |
| 142 + umtx_storeRelease(gHaveTriedToLoadCommonData, 1); |
| 143 } |
| 144 |
| 145 didUpdate = findCommonICUDataByName(U_ICUDATA_NAME); /* Return 'true' when
a racing writes out the extended */ |
| 146 @@ -1398,5 +1409,6 @@ udata_getInfo(UDataMemory *pData, UDataInfo *pInfo) { |
| 147 |
| 148 U_CAPI void U_EXPORT2 udata_setFileAccess(UDataFileAccess access, UErrorCode *
/*status*/) |
| 149 { |
| 150 + // Note: this function is documented as not thread safe. |
| 151 gDataFileAccess = access; |
| 152 } |
OLD | NEW |