2017-01-20 00:20:31 +00:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
2016-06-15 18:58:17 +00:00
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
2001-08-11 00:29:58 +00:00
|
|
|
/*
|
|
|
|
******************************************************************************
|
2016-05-31 21:45:07 +00:00
|
|
|
* Copyright (C) 2001-2014, International Business Machines
|
2010-02-25 00:21:02 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
2001-08-11 00:29:58 +00:00
|
|
|
******************************************************************************
|
2014-04-23 23:22:13 +00:00
|
|
|
* file name: ucln_cmn.cpp
|
2017-02-03 18:57:23 +00:00
|
|
|
* encoding: UTF-8
|
2001-08-11 00:29:58 +00:00
|
|
|
* 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-08-05 01:25:54 +00:00
|
|
|
#include "cmemory.h"
|
2014-04-25 17:27:53 +00:00
|
|
|
#include "mutex.h"
|
2003-09-25 17:58:08 +00:00
|
|
|
#include "uassert.h"
|
2014-04-25 17:27:53 +00:00
|
|
|
#include "ucln.h"
|
|
|
|
#include "ucln_cmn.h"
|
|
|
|
#include "utracimp.h"
|
|
|
|
#include "umutex.h"
|
2001-08-30 02:59:19 +00:00
|
|
|
|
2009-09-03 20:40:02 +00:00
|
|
|
/** Auto-client for UCLN_COMMON **/
|
2011-06-03 05:23:57 +00:00
|
|
|
#define UCLN_TYPE_IS_COMMON
|
2009-09-03 20:40:02 +00:00
|
|
|
#include "ucln_imp.h"
|
|
|
|
|
2004-10-06 23:10:53 +00:00
|
|
|
static cleanupFunc *gCommonCleanupFunctions[UCLN_COMMON_COUNT];
|
2006-03-31 07:11:33 +00:00
|
|
|
static cleanupFunc *gLibCleanupFunctions[UCLN_COMMON];
|
2003-08-21 20:55:02 +00:00
|
|
|
|
2012-08-11 04:57:13 +00:00
|
|
|
|
2011-06-03 05:23:57 +00:00
|
|
|
/************************************************
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
UTRACE_ENTRY_OC(UTRACE_U_CLEANUP);
|
2018-11-01 00:08:38 +00:00
|
|
|
icu::umtx_lock(NULL); /* Force a memory barrier, so that we are sure to see */
|
|
|
|
icu::umtx_unlock(NULL); /* all state left around by any other threads. */
|
2009-09-03 20:40:02 +00:00
|
|
|
|
2011-06-03 05:23:57 +00:00
|
|
|
ucln_lib_cleanup();
|
2009-09-03 20:40:02 +00:00
|
|
|
|
2011-06-03 05:23:57 +00:00
|
|
|
cmemory_cleanup(); /* undo any heap functions set by u_setMemoryFunctions(). */
|
|
|
|
UTRACE_EXIT(); /* Must be before utrace_cleanup(), which turns off tracing. */
|
|
|
|
/*#if U_ENABLE_TRACING*/
|
|
|
|
utrace_cleanup();
|
|
|
|
/*#endif*/
|
|
|
|
}
|
2009-09-03 20:40:02 +00:00
|
|
|
|
2011-06-03 05:23:57 +00:00
|
|
|
U_CAPI void U_EXPORT2 ucln_cleanupOne(ECleanupLibraryType libType)
|
2009-09-03 20:40:02 +00:00
|
|
|
{
|
|
|
|
if (gLibCleanupFunctions[libType])
|
|
|
|
{
|
|
|
|
gLibCleanupFunctions[libType]();
|
|
|
|
gLibCleanupFunctions[libType] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-31 07:11:33 +00:00
|
|
|
U_CFUNC void
|
|
|
|
ucln_common_registerCleanup(ECleanupCommonType type,
|
|
|
|
cleanupFunc *func)
|
2001-08-30 02:59:19 +00:00
|
|
|
{
|
2004-10-06 23:10:53 +00:00
|
|
|
U_ASSERT(UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT);
|
|
|
|
if (UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT)
|
2001-08-30 02:59:19 +00:00
|
|
|
{
|
2014-04-25 17:27:53 +00:00
|
|
|
icu::Mutex m; // See ticket 10295 for discussion.
|
2004-10-06 23:10:53 +00:00
|
|
|
gCommonCleanupFunctions[type] = func;
|
2001-08-30 02:59:19 +00:00
|
|
|
}
|
2009-09-03 20:40:02 +00:00
|
|
|
#if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
|
|
|
|
ucln_registerAutomaticCleanup();
|
|
|
|
#endif
|
2001-08-30 02:59:19 +00:00
|
|
|
}
|
2001-08-11 00:29:58 +00:00
|
|
|
|
2014-04-25 17:27:53 +00:00
|
|
|
// Note: ucln_registerCleanup() is called with the ICU global mutex locked.
|
|
|
|
// Be aware if adding anything to the function.
|
|
|
|
// See ticket 10295 for discussion.
|
|
|
|
|
2006-03-31 07:11:33 +00:00
|
|
|
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) {
|
2014-04-23 23:22:13 +00:00
|
|
|
int32_t libType = UCLN_START;
|
|
|
|
int32_t commonFunc = UCLN_COMMON_START;
|
2004-02-24 00:13:01 +00:00
|
|
|
|
2006-03-31 07:11:33 +00:00
|
|
|
for (libType++; libType<UCLN_COMMON; libType++) {
|
2014-04-23 23:22:13 +00:00
|
|
|
ucln_cleanupOne(static_cast<ECleanupLibraryType>(libType));
|
2006-03-31 07:11:33 +00:00
|
|
|
}
|
|
|
|
|
2006-03-20 07:35:37 +00:00
|
|
|
for (commonFunc++; commonFunc<UCLN_COMMON_COUNT; commonFunc++) {
|
2004-10-06 23:10:53 +00:00
|
|
|
if (gCommonCleanupFunctions[commonFunc])
|
2001-08-30 02:59:19 +00:00
|
|
|
{
|
2004-10-06 23:10:53 +00:00
|
|
|
gCommonCleanupFunctions[commonFunc]();
|
|
|
|
gCommonCleanupFunctions[commonFunc] = NULL;
|
2001-08-30 02:59:19 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-03 20:40:02 +00:00
|
|
|
#if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
|
|
|
|
ucln_unRegisterAutomaticCleanup();
|
|
|
|
#endif
|
2004-10-06 23:10:53 +00:00
|
|
|
return TRUE;
|
2003-04-30 00:09:18 +00:00
|
|
|
}
|