2001-08-11 00:29:58 +00:00
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* *
|
2004-05-18 22:01:41 +00:00
|
|
|
* Copyright (C) 2001-2004, 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-10-31 02:19:42 +00:00
|
|
|
#include "utracimp.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"
|
2003-09-25 17:58:08 +00:00
|
|
|
#include "uassert.h"
|
2001-08-30 02:59:19 +00:00
|
|
|
|
2003-08-21 20:55:02 +00:00
|
|
|
static UBool gICUInitialized = FALSE;
|
2004-01-09 01:07:54 +00:00
|
|
|
static UMTX gICUInitMutex = NULL;
|
2003-08-21 20:55:02 +00:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2003-09-25 17:58:08 +00:00
|
|
|
U_ASSERT(UCLN_START < type && type < UCLN_COMMON);
|
2001-08-30 02:59:19 +00:00
|
|
|
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
|
|
|
{
|
2003-09-25 17:58:08 +00:00
|
|
|
ECleanupLibraryType libType;
|
2001-10-08 23:26:58 +00:00
|
|
|
|
2003-11-01 01:18:42 +00:00
|
|
|
UTRACE_ENTRY_OC(UTRACE_U_CLEANUP);
|
2004-02-24 00:13:01 +00:00
|
|
|
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. */
|
|
|
|
|
2003-09-25 17:58:08 +00:00
|
|
|
for (libType = UCLN_START+1; libType<UCLN_COMMON; libType++) {
|
2001-08-30 02:59:19 +00:00
|
|
|
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-09-25 17:58:08 +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;
|
2003-09-25 17:58:08 +00:00
|
|
|
UTRACE_EXIT(); /* Must be before utrace_cleanup(), which turns off tracing. */
|
|
|
|
utrace_cleanup();
|
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-11-01 01:18:42 +00:00
|
|
|
UTRACE_ENTRY_OC(UTRACE_U_INIT);
|
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);
|
2003-11-01 01:18:42 +00:00
|
|
|
UTRACE_EXIT_STATUS(*status);
|
2003-08-21 20:55:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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-11-01 01:18:42 +00:00
|
|
|
UTRACE_EXIT_STATUS(*status);
|
2003-04-30 00:09:18 +00:00
|
|
|
}
|
2003-08-05 01:25:54 +00:00
|
|
|
|