2001-08-11 00:29:58 +00:00
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* *
|
2003-05-06 01:37:52 +00:00
|
|
|
* Copyright (C) 2001-2003, International Business Machines *
|
2001-08-11 00:29:58 +00:00
|
|
|
* Corporation and others. All Rights Reserved. *
|
|
|
|
* *
|
|
|
|
******************************************************************************
|
|
|
|
* file name: ucln_cmn.c
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2001July05
|
|
|
|
* created by: George Rhoten
|
|
|
|
*/
|
|
|
|
|
2003-05-06 01:37:52 +00:00
|
|
|
#include "unicode/utypes.h"
|
2001-08-11 00:29:58 +00:00
|
|
|
#include "unicode/uclean.h"
|
2003-05-06 01:37:52 +00:00
|
|
|
#include "ustr_imp.h"
|
2003-05-02 21:33:17 +00:00
|
|
|
#include "unormimp.h"
|
2001-08-11 00:29:58 +00:00
|
|
|
#include "ucln_cmn.h"
|
|
|
|
#include "umutex.h"
|
2001-08-30 02:59:19 +00:00
|
|
|
#include "ucln.h"
|
2003-08-05 01:25:54 +00:00
|
|
|
#include "cmemory.h"
|
2001-08-30 02:59:19 +00:00
|
|
|
|
2003-08-21 20:55:02 +00:00
|
|
|
static UBool gICUInitialized = FALSE;
|
|
|
|
static UMTX gICUInitMutex;
|
|
|
|
|
|
|
|
|
2001-08-30 02:59:19 +00:00
|
|
|
static cleanupFunc *gCleanupFunctions[UCLN_COMMON] = {
|
2003-06-06 22:50:26 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2001-08-30 02:59:19 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
ucln_registerCleanup(ECleanupLibraryType type,
|
|
|
|
cleanupFunc *func)
|
|
|
|
{
|
|
|
|
if (UCLN_START < type && type < UCLN_COMMON)
|
|
|
|
{
|
|
|
|
gCleanupFunctions[type] = func;
|
|
|
|
}
|
|
|
|
}
|
2001-08-11 00:29:58 +00:00
|
|
|
|
2003-03-20 00:08:40 +00:00
|
|
|
/************************************************
|
|
|
|
The cleanup order is important in this function.
|
|
|
|
Please be sure that you have read ucln.h
|
|
|
|
************************************************/
|
2001-11-21 01:02:11 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
u_cleanup(void)
|
2001-08-11 00:29:58 +00:00
|
|
|
{
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2001-08-30 02:59:19 +00:00
|
|
|
ECleanupLibraryType libType = UCLN_START;
|
|
|
|
while (++libType < UCLN_COMMON)
|
|
|
|
{
|
|
|
|
if (gCleanupFunctions[libType])
|
|
|
|
{
|
|
|
|
gCleanupFunctions[libType]();
|
2003-08-21 20:55:02 +00:00
|
|
|
gCleanupFunctions[libType] = NULL;
|
2001-08-30 02:59:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2003-05-06 01:37:52 +00:00
|
|
|
#if !UCONFIG_NO_IDNA
|
2003-07-24 23:23:19 +00:00
|
|
|
usprep_cleanup();
|
2003-05-06 01:37:52 +00:00
|
|
|
#endif
|
2002-12-05 19:28:09 +00:00
|
|
|
#if !UCONFIG_NO_BREAK_ITERATION
|
2002-11-08 18:07:48 +00:00
|
|
|
breakiterator_cleanup();
|
2002-12-05 19:28:09 +00:00
|
|
|
#endif
|
2002-12-06 00:22:10 +00:00
|
|
|
#if !UCONFIG_NO_SERVICE
|
|
|
|
service_cleanup();
|
|
|
|
#endif
|
2003-03-20 00:08:40 +00:00
|
|
|
ures_cleanup();
|
|
|
|
locale_cleanup();
|
|
|
|
uloc_cleanup();
|
2003-05-06 01:37:52 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
2003-03-20 00:08:40 +00:00
|
|
|
unorm_cleanup();
|
2003-05-06 01:37:52 +00:00
|
|
|
#endif
|
2003-03-20 00:08:40 +00:00
|
|
|
uset_cleanup();
|
|
|
|
unames_cleanup();
|
|
|
|
pname_cleanup();
|
|
|
|
uchar_cleanup();
|
2001-08-25 01:13:21 +00:00
|
|
|
ucnv_cleanup();
|
|
|
|
ucnv_io_cleanup();
|
2001-08-17 00:18:49 +00:00
|
|
|
udata_cleanup();
|
2001-08-31 02:14:47 +00:00
|
|
|
putil_cleanup();
|
2003-08-21 20:55:02 +00:00
|
|
|
|
|
|
|
umtx_destroy(&gICUInitMutex);
|
2003-08-08 16:23:38 +00:00
|
|
|
umtx_cleanup();
|
2003-08-05 01:25:54 +00:00
|
|
|
cmemory_cleanup(); /* undo any heap functions set by u_setMemoryFunctions(). */
|
2003-08-21 20:55:02 +00:00
|
|
|
gICUInitialized = FALSE;
|
2001-08-17 00:18:49 +00:00
|
|
|
}
|
|
|
|
|
2003-04-30 00:09:18 +00:00
|
|
|
|
2003-05-02 21:33:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* ICU Initialization Function. Force loading and/or initialization of
|
|
|
|
* any shared data that could potentially be used concurrently
|
2003-05-07 00:02:29 +00:00
|
|
|
* by multiple threads.
|
2003-05-02 21:33:17 +00:00
|
|
|
*/
|
2003-04-30 00:09:18 +00:00
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
u_init(UErrorCode *status) {
|
2003-06-12 22:48:09 +00:00
|
|
|
/* Make sure the global mutexes are initialized. */
|
2003-08-21 20:55:02 +00:00
|
|
|
umtx_init(NULL);
|
|
|
|
umtx_lock(&gICUInitMutex);
|
|
|
|
if (gICUInitialized || U_FAILURE(*status)) {
|
|
|
|
umtx_unlock(&gICUInitMutex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ucnv_init(status);
|
|
|
|
ures_init(status);
|
2003-05-07 00:02:29 +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).
|
2003-04-30 00:09:18 +00:00
|
|
|
*/
|
2003-05-02 21:33:17 +00:00
|
|
|
|
2003-04-30 00:09:18 +00:00
|
|
|
/* Char Properties */
|
2003-08-22 23:26:53 +00:00
|
|
|
uprv_loadPropsData(status);
|
2003-04-30 00:09:18 +00:00
|
|
|
|
2003-05-06 01:37:52 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
2003-05-02 21:33:17 +00:00
|
|
|
/* Normalization */
|
|
|
|
unorm_haveData(status);
|
2003-05-06 01:37:52 +00:00
|
|
|
#endif
|
2003-08-21 20:55:02 +00:00
|
|
|
gICUInitialized = TRUE; /* TODO: don't set if U_FAILURE? */
|
|
|
|
umtx_unlock(&gICUInitMutex);
|
2003-04-30 00:09:18 +00:00
|
|
|
}
|
2003-08-05 01:25:54 +00:00
|
|
|
|
|
|
|
|
2003-08-21 20:55:02 +00:00
|
|
|
U_CFUNC UBool u_isUInit() {
|
|
|
|
return gICUInitialized;
|
2003-08-05 01:25:54 +00:00
|
|
|
}
|