2004-10-06 23:10:53 +00:00
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* *
|
2005-02-23 00:54:19 +00:00
|
|
|
* Copyright (C) 2001-2005, International Business Machines *
|
2004-10-06 23:10:53 +00:00
|
|
|
* Corporation and others. All Rights Reserved. *
|
|
|
|
* *
|
|
|
|
******************************************************************************
|
|
|
|
* file name: uinit.c
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2001July05
|
|
|
|
* created by: George Rhoten
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uclean.h"
|
|
|
|
#include "utracimp.h"
|
|
|
|
#include "ustr_imp.h"
|
|
|
|
#include "unormimp.h"
|
|
|
|
#include "ucln_cmn.h"
|
2005-05-03 22:59:01 +00:00
|
|
|
#include "ucnv_io.h"
|
2004-10-06 23:10:53 +00:00
|
|
|
#include "umutex.h"
|
|
|
|
#include "ucln.h"
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "uassert.h"
|
|
|
|
|
|
|
|
static UBool gICUInitialized = FALSE;
|
|
|
|
static UMTX gICUInitMutex = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
static cleanupFunc *gLibCleanupFunctions[UCLN_COMMON];
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucln_registerCleanup(ECleanupLibraryType type,
|
|
|
|
cleanupFunc *func)
|
|
|
|
{
|
|
|
|
U_ASSERT(UCLN_START < type && type < UCLN_COMMON);
|
|
|
|
if (UCLN_START < type && type < UCLN_COMMON)
|
|
|
|
{
|
|
|
|
gLibCleanupFunctions[type] = func;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************
|
|
|
|
The cleanup order is important in this function.
|
|
|
|
Please be sure that you have read ucln.h
|
|
|
|
************************************************/
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
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 (gLibCleanupFunctions[libType])
|
|
|
|
{
|
|
|
|
gLibCleanupFunctions[libType]();
|
|
|
|
gLibCleanupFunctions[libType] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ucln_common_lib_cleanup();
|
|
|
|
|
|
|
|
umtx_destroy(&gICUInitMutex);
|
|
|
|
umtx_cleanup();
|
|
|
|
cmemory_cleanup(); /* undo any heap functions set by u_setMemoryFunctions(). */
|
|
|
|
gICUInitialized = FALSE;
|
|
|
|
UTRACE_EXIT(); /* Must be before utrace_cleanup(), which turns off tracing. */
|
2004-12-10 00:12:11 +00:00
|
|
|
#if U_ENABLE_TRACING
|
2004-10-06 23:10:53 +00:00
|
|
|
utrace_cleanup();
|
2004-12-10 00:12:11 +00:00
|
|
|
#endif
|
2004-10-06 23:10:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* ICU Initialization Function. Force loading and/or initialization of
|
|
|
|
* any shared data that could potentially be used concurrently
|
|
|
|
* by multiple threads.
|
|
|
|
*/
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
u_init(UErrorCode *status) {
|
|
|
|
UTRACE_ENTRY_OC(UTRACE_U_INIT);
|
|
|
|
/* Make sure the global mutexes are initialized. */
|
|
|
|
umtx_init(NULL);
|
|
|
|
umtx_lock(&gICUInitMutex);
|
|
|
|
if (gICUInitialized || U_FAILURE(*status)) {
|
|
|
|
umtx_unlock(&gICUInitMutex);
|
|
|
|
UTRACE_EXIT_STATUS(*status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-05-03 22:59:01 +00:00
|
|
|
#if 1
|
|
|
|
/*
|
|
|
|
* 2005-may-02
|
|
|
|
*
|
|
|
|
* ICU4C 3.4 (jitterbug 4497) hardcodes the data for Unicode character
|
|
|
|
* properties for APIs that want to be fast.
|
|
|
|
* Therefore, we need not load them here nor check for errors.
|
|
|
|
* Instead, we load the converter alias table to see if any ICU data
|
|
|
|
* is available.
|
|
|
|
* Users should really open the service objects they need and check
|
|
|
|
* for errors there, to make sure that the actual items they need are
|
|
|
|
* available.
|
|
|
|
*/
|
|
|
|
#if !UCONFIG_NO_CONVERSION
|
2005-08-30 20:37:50 +00:00
|
|
|
ucnv_io_countTotalAliases(status);
|
2005-05-03 22:59:01 +00:00
|
|
|
#endif
|
|
|
|
#else
|
2004-10-06 23:10:53 +00:00
|
|
|
/* Do any required init for services that don't have open operations
|
|
|
|
* and use "only" the double-check initialization method for performance
|
|
|
|
* reasons (avoiding a mutex lock even for _checking_ whether the
|
|
|
|
* initialization had occurred).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Char Properties */
|
|
|
|
uprv_loadPropsData(status);
|
|
|
|
|
2005-02-23 00:54:19 +00:00
|
|
|
/* load the case and bidi properties but don't fail if they are not available */
|
|
|
|
u_isULowercase(0x61);
|
|
|
|
u_getIntPropertyValue(0x200D, UCHAR_JOINING_TYPE); /* ZERO WIDTH JOINER: Join_Causing */
|
|
|
|
|
2004-10-06 23:10:53 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
|
|
|
/* Normalization */
|
|
|
|
unorm_haveData(status);
|
2005-05-03 22:59:01 +00:00
|
|
|
#endif
|
2004-10-06 23:10:53 +00:00
|
|
|
#endif
|
|
|
|
gICUInitialized = TRUE; /* TODO: don't set if U_FAILURE? */
|
|
|
|
umtx_unlock(&gICUInitMutex);
|
|
|
|
UTRACE_EXIT_STATUS(*status);
|
|
|
|
}
|
|
|
|
|