ICU-5138 Separate cleaning registration from the uinit() implementation.

X-SVN-Rev: 19502
This commit is contained in:
George Rhoten 2006-03-31 07:11:33 +00:00
parent 9b0162b829
commit 01aff246f1
3 changed files with 27 additions and 28 deletions

View file

@ -26,9 +26,11 @@
#include "uassert.h"
static cleanupFunc *gCommonCleanupFunctions[UCLN_COMMON_COUNT];
static cleanupFunc *gLibCleanupFunctions[UCLN_COMMON];
void ucln_common_registerCleanup(ECleanupCommonType type,
cleanupFunc *func)
U_CFUNC void
ucln_common_registerCleanup(ECleanupCommonType type,
cleanupFunc *func)
{
U_ASSERT(UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT);
if (UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT)
@ -37,9 +39,29 @@ void ucln_common_registerCleanup(ECleanupCommonType type,
}
}
U_CFUNC UBool ucln_common_lib_cleanup(void) {
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;
}
}
U_CFUNC UBool ucln_lib_cleanup(void) {
ECleanupLibraryType libType = UCLN_START;
ECleanupCommonType commonFunc = UCLN_COMMON_START;
for (libType++; libType<UCLN_COMMON; libType++) {
if (gLibCleanupFunctions[libType])
{
gLibCleanupFunctions[libType]();
gLibCleanupFunctions[libType] = NULL;
}
}
for (commonFunc++; commonFunc<UCLN_COMMON_COUNT; commonFunc++) {
if (gCommonCleanupFunctions[commonFunc])
{

View file

@ -26,7 +26,7 @@ U_CFUNC UBool umtx_cleanup(void);
U_CFUNC UBool utrace_cleanup(void);
U_CFUNC UBool ucln_common_lib_cleanup(void);
U_CFUNC UBool ucln_lib_cleanup(void);
/*
Please keep the order of enums declared in same order

View file

@ -30,19 +30,6 @@ 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
@ -50,21 +37,11 @@ ucln_registerCleanup(ECleanupLibraryType type,
U_CAPI void U_EXPORT2
u_cleanup(void)
{
ECleanupLibraryType libType = UCLN_START;
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++; libType<UCLN_COMMON; libType++) {
if (gLibCleanupFunctions[libType])
{
gLibCleanupFunctions[libType]();
gLibCleanupFunctions[libType] = NULL;
}
}
ucln_common_lib_cleanup();
ucln_lib_cleanup();
umtx_destroy(&gICUInitMutex);
umtx_cleanup();