#include "unicode/utypes.h"
#include "unicode/uclean.h"
#include "cmemory.h"
#include "mutex.h"
#include "uassert.h"
#include "ucln.h"
#include "ucln_cmn.h"
#include "utracimp.h"
#include "umutex.h"
#define UCLN_TYPE_IS_COMMON
#include "ucln_imp.h"
static cleanupFunc *gCommonCleanupFunctions[UCLN_COMMON_COUNT];
static cleanupFunc *gLibCleanupFunctions[UCLN_COMMON];
U_CAPI void U_EXPORT2
u_cleanup(void)
{
UTRACE_ENTRY_OC(UTRACE_U_CLEANUP);
icu::umtx_lock(NULL);
icu::umtx_unlock(NULL);
ucln_lib_cleanup();
cmemory_cleanup();
UTRACE_EXIT();
utrace_cleanup();
}
U_CAPI void U_EXPORT2 ucln_cleanupOne(ECleanupLibraryType libType)
{
if (gLibCleanupFunctions[libType])
{
gLibCleanupFunctions[libType]();
gLibCleanupFunctions[libType] = NULL;
}
}
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)
{
icu::Mutex m; gCommonCleanupFunctions[type] = func;
}
#if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
ucln_registerAutomaticCleanup();
#endif
}
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) {
int32_t libType = UCLN_START;
int32_t commonFunc = UCLN_COMMON_START;
for (libType++; libType<UCLN_COMMON; libType++) {
ucln_cleanupOne(static_cast<ECleanupLibraryType>(libType));
}
for (commonFunc++; commonFunc<UCLN_COMMON_COUNT; commonFunc++) {
if (gCommonCleanupFunctions[commonFunc])
{
gCommonCleanupFunctions[commonFunc]();
gCommonCleanupFunctions[commonFunc] = NULL;
}
}
#if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
ucln_unRegisterAutomaticCleanup();
#endif
return TRUE;
}