2 ******************************************************************************
3 * Copyright (C) 2001-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ******************************************************************************
6 * file name: ucln_cmn.c
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"
24 /** Auto-client for UCLN_COMMON **/
25 #define UCLN_TYPE_IS_COMMON
30 UBool gICUInitialized
= FALSE
;
31 UMTX gICUInitMutex
= NULL
;
35 static cleanupFunc
*gCommonCleanupFunctions
[UCLN_COMMON_COUNT
];
36 static cleanupFunc
*gLibCleanupFunctions
[UCLN_COMMON
];
38 /************************************************
39 The cleanup order is important in this function.
40 Please be sure that you have read ucln.h
41 ************************************************/
45 UTRACE_ENTRY_OC(UTRACE_U_CLEANUP
);
46 umtx_lock(NULL
); /* Force a memory barrier, so that we are sure to see */
47 umtx_unlock(NULL
); /* all state left around by any other threads. */
51 umtx_destroy(&gICUInitMutex
);
53 cmemory_cleanup(); /* undo any heap functions set by u_setMemoryFunctions(). */
54 gICUInitialized
= FALSE
;
55 UTRACE_EXIT(); /* Must be before utrace_cleanup(), which turns off tracing. */
56 /*#if U_ENABLE_TRACING*/
61 U_CAPI
void U_EXPORT2
ucln_cleanupOne(ECleanupLibraryType libType
)
63 if (gLibCleanupFunctions
[libType
])
65 gLibCleanupFunctions
[libType
]();
66 gLibCleanupFunctions
[libType
] = NULL
;
71 ucln_common_registerCleanup(ECleanupCommonType type
,
74 U_ASSERT(UCLN_COMMON_START
< type
&& type
< UCLN_COMMON_COUNT
);
75 if (UCLN_COMMON_START
< type
&& type
< UCLN_COMMON_COUNT
)
77 gCommonCleanupFunctions
[type
] = func
;
79 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
80 ucln_registerAutomaticCleanup();
85 ucln_registerCleanup(ECleanupLibraryType type
,
88 U_ASSERT(UCLN_START
< type
&& type
< UCLN_COMMON
);
89 if (UCLN_START
< type
&& type
< UCLN_COMMON
)
91 gLibCleanupFunctions
[type
] = func
;
95 U_CFUNC UBool
ucln_lib_cleanup(void) {
96 ECleanupLibraryType libType
= UCLN_START
;
97 ECleanupCommonType commonFunc
= UCLN_COMMON_START
;
99 for (libType
++; libType
<UCLN_COMMON
; libType
++) {
100 ucln_cleanupOne(libType
);
103 for (commonFunc
++; commonFunc
<UCLN_COMMON_COUNT
; commonFunc
++) {
104 if (gCommonCleanupFunctions
[commonFunc
])
106 gCommonCleanupFunctions
[commonFunc
]();
107 gCommonCleanupFunctions
[commonFunc
] = NULL
;
110 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
111 ucln_unRegisterAutomaticCleanup();