1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
5 * Copyright (C) 2001-2014, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
8 * file name: ucln_cmn.cpp
10 * tab size: 8 (not used)
13 * created on: 2001July05
14 * created by: George Rhoten
17 #include "unicode/utypes.h"
18 #include "unicode/uclean.h"
27 /** Auto-client for UCLN_COMMON **/
28 #define UCLN_TYPE_IS_COMMON
31 static cleanupFunc
*gCommonCleanupFunctions
[UCLN_COMMON_COUNT
];
32 static cleanupFunc
*gLibCleanupFunctions
[UCLN_COMMON
];
35 /************************************************
36 The cleanup order is important in this function.
37 Please be sure that you have read ucln.h
38 ************************************************/
42 UTRACE_ENTRY_OC(UTRACE_U_CLEANUP
);
43 icu::umtx_lock(NULL
); /* Force a memory barrier, so that we are sure to see */
44 icu::umtx_unlock(NULL
); /* all state left around by any other threads. */
48 cmemory_cleanup(); /* undo any heap functions set by u_setMemoryFunctions(). */
49 UTRACE_EXIT(); /* Must be before utrace_cleanup(), which turns off tracing. */
50 /*#if U_ENABLE_TRACING*/
55 U_CAPI
void U_EXPORT2
ucln_cleanupOne(ECleanupLibraryType libType
)
57 if (gLibCleanupFunctions
[libType
])
59 gLibCleanupFunctions
[libType
]();
60 gLibCleanupFunctions
[libType
] = NULL
;
65 ucln_common_registerCleanup(ECleanupCommonType type
,
68 U_ASSERT(UCLN_COMMON_START
< type
&& type
< UCLN_COMMON_COUNT
);
69 if (UCLN_COMMON_START
< type
&& type
< UCLN_COMMON_COUNT
)
71 icu::Mutex m
; // See ticket 10295 for discussion.
72 gCommonCleanupFunctions
[type
] = func
;
74 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
75 ucln_registerAutomaticCleanup();
79 // Note: ucln_registerCleanup() is called with the ICU global mutex locked.
80 // Be aware if adding anything to the function.
81 // See ticket 10295 for discussion.
84 ucln_registerCleanup(ECleanupLibraryType type
,
87 U_ASSERT(UCLN_START
< type
&& type
< UCLN_COMMON
);
88 if (UCLN_START
< type
&& type
< UCLN_COMMON
)
90 gLibCleanupFunctions
[type
] = func
;
94 U_CFUNC UBool
ucln_lib_cleanup(void) {
95 int32_t libType
= UCLN_START
;
96 int32_t commonFunc
= UCLN_COMMON_START
;
98 for (libType
++; libType
<UCLN_COMMON
; libType
++) {
99 ucln_cleanupOne(static_cast<ECleanupLibraryType
>(libType
));
102 for (commonFunc
++; commonFunc
<UCLN_COMMON_COUNT
; commonFunc
++) {
103 if (gCommonCleanupFunctions
[commonFunc
])
105 gCommonCleanupFunctions
[commonFunc
]();
106 gCommonCleanupFunctions
[commonFunc
] = NULL
;
109 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
110 ucln_unRegisterAutomaticCleanup();