2 ******************************************************************************
3 * Copyright (C) 2001-2014, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ******************************************************************************
6 * file name: ucln_cmn.cpp
8 * tab size: 8 (not used)
11 * created on: 2001July05
12 * created by: George Rhoten
15 #include "unicode/utypes.h"
16 #include "unicode/uclean.h"
25 /** Auto-client for UCLN_COMMON **/
26 #define UCLN_TYPE_IS_COMMON
29 static cleanupFunc
*gCommonCleanupFunctions
[UCLN_COMMON_COUNT
];
30 static cleanupFunc
*gLibCleanupFunctions
[UCLN_COMMON
];
33 /************************************************
34 The cleanup order is important in this function.
35 Please be sure that you have read ucln.h
36 ************************************************/
40 UTRACE_ENTRY_OC(UTRACE_U_CLEANUP
);
41 umtx_lock(NULL
); /* Force a memory barrier, so that we are sure to see */
42 umtx_unlock(NULL
); /* all state left around by any other threads. */
46 cmemory_cleanup(); /* undo any heap functions set by u_setMemoryFunctions(). */
47 UTRACE_EXIT(); /* Must be before utrace_cleanup(), which turns off tracing. */
48 /*#if U_ENABLE_TRACING*/
53 U_CAPI
void U_EXPORT2
ucln_cleanupOne(ECleanupLibraryType libType
)
55 if (gLibCleanupFunctions
[libType
])
57 gLibCleanupFunctions
[libType
]();
58 gLibCleanupFunctions
[libType
] = NULL
;
63 ucln_common_registerCleanup(ECleanupCommonType type
,
66 U_ASSERT(UCLN_COMMON_START
< type
&& type
< UCLN_COMMON_COUNT
);
67 if (UCLN_COMMON_START
< type
&& type
< UCLN_COMMON_COUNT
)
69 icu::Mutex m
; // See ticket 10295 for discussion.
70 gCommonCleanupFunctions
[type
] = func
;
72 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
73 ucln_registerAutomaticCleanup();
77 // Note: ucln_registerCleanup() is called with the ICU global mutex locked.
78 // Be aware if adding anything to the function.
79 // See ticket 10295 for discussion.
82 ucln_registerCleanup(ECleanupLibraryType type
,
85 U_ASSERT(UCLN_START
< type
&& type
< UCLN_COMMON
);
86 if (UCLN_START
< type
&& type
< UCLN_COMMON
)
88 gLibCleanupFunctions
[type
] = func
;
92 U_CFUNC UBool
ucln_lib_cleanup(void) {
93 int32_t libType
= UCLN_START
;
94 int32_t commonFunc
= UCLN_COMMON_START
;
96 for (libType
++; libType
<UCLN_COMMON
; libType
++) {
97 ucln_cleanupOne(static_cast<ECleanupLibraryType
>(libType
));
100 for (commonFunc
++; commonFunc
<UCLN_COMMON_COUNT
; commonFunc
++) {
101 if (gCommonCleanupFunctions
[commonFunc
])
103 gCommonCleanupFunctions
[commonFunc
]();
104 gCommonCleanupFunctions
[commonFunc
] = NULL
;
107 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
108 ucln_unRegisterAutomaticCleanup();