1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/ucln_cmn.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,105 @@ 1.4 +/* 1.5 +****************************************************************************** 1.6 +* Copyright (C) 2001-2013, International Business Machines 1.7 +* Corporation and others. All Rights Reserved. 1.8 +****************************************************************************** 1.9 +* file name: ucln_cmn.c 1.10 +* encoding: US-ASCII 1.11 +* tab size: 8 (not used) 1.12 +* indentation:4 1.13 +* 1.14 +* created on: 2001July05 1.15 +* created by: George Rhoten 1.16 +*/ 1.17 + 1.18 +#include "unicode/utypes.h" 1.19 +#include "unicode/uclean.h" 1.20 +#include "utracimp.h" 1.21 +#include "ucln_cmn.h" 1.22 +#include "cmutex.h" 1.23 +#include "ucln.h" 1.24 +#include "cmemory.h" 1.25 +#include "uassert.h" 1.26 + 1.27 +/** Auto-client for UCLN_COMMON **/ 1.28 +#define UCLN_TYPE_IS_COMMON 1.29 +#include "ucln_imp.h" 1.30 + 1.31 +static cleanupFunc *gCommonCleanupFunctions[UCLN_COMMON_COUNT]; 1.32 +static cleanupFunc *gLibCleanupFunctions[UCLN_COMMON]; 1.33 + 1.34 + 1.35 +/************************************************ 1.36 + The cleanup order is important in this function. 1.37 + Please be sure that you have read ucln.h 1.38 + ************************************************/ 1.39 +U_CAPI void U_EXPORT2 1.40 +u_cleanup(void) 1.41 +{ 1.42 + UTRACE_ENTRY_OC(UTRACE_U_CLEANUP); 1.43 + umtx_lock(NULL); /* Force a memory barrier, so that we are sure to see */ 1.44 + umtx_unlock(NULL); /* all state left around by any other threads. */ 1.45 + 1.46 + ucln_lib_cleanup(); 1.47 + 1.48 + cmemory_cleanup(); /* undo any heap functions set by u_setMemoryFunctions(). */ 1.49 + UTRACE_EXIT(); /* Must be before utrace_cleanup(), which turns off tracing. */ 1.50 +/*#if U_ENABLE_TRACING*/ 1.51 + utrace_cleanup(); 1.52 +/*#endif*/ 1.53 +} 1.54 + 1.55 +U_CAPI void U_EXPORT2 ucln_cleanupOne(ECleanupLibraryType libType) 1.56 +{ 1.57 + if (gLibCleanupFunctions[libType]) 1.58 + { 1.59 + gLibCleanupFunctions[libType](); 1.60 + gLibCleanupFunctions[libType] = NULL; 1.61 + } 1.62 +} 1.63 + 1.64 +U_CFUNC void 1.65 +ucln_common_registerCleanup(ECleanupCommonType type, 1.66 + cleanupFunc *func) 1.67 +{ 1.68 + U_ASSERT(UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT); 1.69 + if (UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT) 1.70 + { 1.71 + gCommonCleanupFunctions[type] = func; 1.72 + } 1.73 +#if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL)) 1.74 + ucln_registerAutomaticCleanup(); 1.75 +#endif 1.76 +} 1.77 + 1.78 +U_CAPI void U_EXPORT2 1.79 +ucln_registerCleanup(ECleanupLibraryType type, 1.80 + cleanupFunc *func) 1.81 +{ 1.82 + U_ASSERT(UCLN_START < type && type < UCLN_COMMON); 1.83 + if (UCLN_START < type && type < UCLN_COMMON) 1.84 + { 1.85 + gLibCleanupFunctions[type] = func; 1.86 + } 1.87 +} 1.88 + 1.89 +U_CFUNC UBool ucln_lib_cleanup(void) { 1.90 + ECleanupLibraryType libType = UCLN_START; 1.91 + ECleanupCommonType commonFunc = UCLN_COMMON_START; 1.92 + 1.93 + for (libType++; libType<UCLN_COMMON; libType++) { 1.94 + ucln_cleanupOne(libType); 1.95 + } 1.96 + 1.97 + for (commonFunc++; commonFunc<UCLN_COMMON_COUNT; commonFunc++) { 1.98 + if (gCommonCleanupFunctions[commonFunc]) 1.99 + { 1.100 + gCommonCleanupFunctions[commonFunc](); 1.101 + gCommonCleanupFunctions[commonFunc] = NULL; 1.102 + } 1.103 + } 1.104 +#if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL)) 1.105 + ucln_unRegisterAutomaticCleanup(); 1.106 +#endif 1.107 + return TRUE; 1.108 +}