ICU-5349 Use UMTX_CHECK when it's helpful.
X-SVN-Rev: 20271
This commit is contained in:
parent
5988c8fbae
commit
fdf9a9dbc2
@ -45,7 +45,7 @@
|
||||
#include "unicode/tblcoll.h"
|
||||
#include "ucol_imp.h"
|
||||
#include "cmemory.h"
|
||||
#include "mutex.h"
|
||||
#include "umutex.h"
|
||||
#include "servloc.h"
|
||||
#include "ustrenum.h"
|
||||
#include "ucln_in.h"
|
||||
@ -184,18 +184,16 @@ static ICULocaleService*
|
||||
getService(void)
|
||||
{
|
||||
UBool needInit;
|
||||
{
|
||||
Mutex mutex;
|
||||
needInit = (UBool)(gService == NULL);
|
||||
}
|
||||
UMTX_CHECK(NULL, (UBool)(gService == NULL), needInit);
|
||||
if(needInit) {
|
||||
ICULocaleService *newservice = new ICUCollatorService();
|
||||
if(newservice) {
|
||||
Mutex mutex;
|
||||
umtx_lock(NULL);
|
||||
if(gService == NULL) {
|
||||
gService = newservice;
|
||||
newservice = NULL;
|
||||
}
|
||||
umtx_unlock(NULL);
|
||||
}
|
||||
if(newservice) {
|
||||
delete newservice;
|
||||
@ -211,11 +209,12 @@ getService(void)
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
static UBool
|
||||
static inline UBool
|
||||
hasService(void)
|
||||
{
|
||||
Mutex mutex;
|
||||
return gService != NULL;
|
||||
UBool retVal;
|
||||
UMTX_CHECK(NULL, gService != NULL, retVal);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
|
@ -362,13 +362,18 @@ static UBool loadOlsonIDs() {
|
||||
const TimeZone* U_EXPORT2
|
||||
TimeZone::getGMT(void)
|
||||
{
|
||||
umtx_init(&LOCK); /* This is here to prevent race conditions. */
|
||||
Mutex lock(&LOCK);
|
||||
UBool needsInit;
|
||||
UMTX_CHECK(&LOCK, (_GMT == NULL), needsInit); /* This is here to prevent race conditions. */
|
||||
|
||||
// Initialize _GMT independently of other static data; it should
|
||||
// be valid even if we can't load the time zone UDataMemory.
|
||||
if (_GMT == 0) {
|
||||
_GMT = new SimpleTimeZone(0, UnicodeString(GMT_ID, GMT_ID_LENGTH));
|
||||
ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
|
||||
if (needsInit) {
|
||||
umtx_lock(&LOCK);
|
||||
if (_GMT == 0) {
|
||||
_GMT = new SimpleTimeZone(0, UnicodeString(TRUE, GMT_ID, GMT_ID_LENGTH));
|
||||
ucln_i18n_registerCleanup(UCLN_I18N_TIMEZONE, timeZone_cleanup);
|
||||
}
|
||||
umtx_unlock(&LOCK);
|
||||
}
|
||||
return _GMT;
|
||||
}
|
||||
@ -506,7 +511,7 @@ TimeZone::initDefault()
|
||||
// Some of the locale/timezone OS functions may not be thread safe,
|
||||
// so the intent is that any setting from anywhere within ICU
|
||||
// happens with the ICU global mutex held.
|
||||
Mutex lock;
|
||||
Mutex lock;
|
||||
uprv_tzset(); // Initialize tz... system data
|
||||
|
||||
// Get the timezone ID from the host. This function should do
|
||||
|
Loading…
Reference in New Issue
Block a user