mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-2787 revise double-check code to improve thread safety
X-SVN-Rev: 11845
This commit is contained in:
parent
1a249cc5be
commit
cacf3d2b39
1 changed files with 33 additions and 17 deletions
|
@ -121,28 +121,44 @@ pname_cleanup() {
|
|||
}
|
||||
U_CDECL_END
|
||||
|
||||
static UBool load() {
|
||||
if (!PNAME) {
|
||||
UErrorCode ec = U_ZERO_ERROR;
|
||||
UDataMemory* data =
|
||||
udata_openChoice(0, PNAME_DATA_TYPE, PNAME_DATA_NAME,
|
||||
isAcceptable, 0, &ec);
|
||||
if (U_SUCCESS(ec)) {
|
||||
umtx_lock(NULL);
|
||||
if (UDATA == NULL) {
|
||||
UDATA = data;
|
||||
PNAME = (const PropertyAliases*) udata_getMemory(UDATA);
|
||||
data = NULL;
|
||||
}
|
||||
umtx_unlock(NULL);
|
||||
}
|
||||
if (data) {
|
||||
udata_close(data);
|
||||
/**
|
||||
* Load the property names data. Caller should check that data is
|
||||
* not loaded BEFORE calling this function. Returns TRUE if the load
|
||||
* succeeds.
|
||||
*/
|
||||
static UBool _load() {
|
||||
UErrorCode ec = U_ZERO_ERROR;
|
||||
UDataMemory* data =
|
||||
udata_openChoice(0, PNAME_DATA_TYPE, PNAME_DATA_NAME,
|
||||
isAcceptable, 0, &ec);
|
||||
if (U_SUCCESS(ec)) {
|
||||
umtx_lock(NULL);
|
||||
if (UDATA == NULL) {
|
||||
UDATA = data;
|
||||
PNAME = (const PropertyAliases*) udata_getMemory(UDATA);
|
||||
data = NULL;
|
||||
}
|
||||
umtx_unlock(NULL);
|
||||
}
|
||||
if (data) {
|
||||
udata_close(data);
|
||||
}
|
||||
return PNAME!=NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inline function that expands to code that does a lazy load of the
|
||||
* property names data. If the data is already loaded, avoids an
|
||||
* unnecessary function call. If the data is not loaded, call _load()
|
||||
* to load it, and return TRUE if the load succeeds.
|
||||
*/
|
||||
static UBool inline load() {
|
||||
umtx_lock(NULL);
|
||||
UBool f = (PNAME!=NULL);
|
||||
umtx_unlock(NULL);
|
||||
return f || _load();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// Public API implementation
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue