2 ******************************************************************************
3 * Copyright (C) 2001-2010, 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"
25 /** Auto-client for UCLN_COMMON **/
26 #define UCLN_TYPE UCLN_COMMON
29 static cleanupFunc
*gCommonCleanupFunctions
[UCLN_COMMON_COUNT
];
30 static cleanupFunc
*gLibCleanupFunctions
[UCLN_COMMON
];
33 /* Enables debugging information about when a library is cleaned up. */
34 #ifndef UCLN_DEBUG_CLEANUP
35 #define UCLN_DEBUG_CLEANUP 0
39 #if defined(UCLN_DEBUG_CLEANUP)
43 static void ucln_cleanup_internal(ECleanupLibraryType libType
)
45 if (gLibCleanupFunctions
[libType
])
47 gLibCleanupFunctions
[libType
]();
48 gLibCleanupFunctions
[libType
] = NULL
;
52 U_CAPI
void U_EXPORT2
ucln_cleanupOne(ECleanupLibraryType libType
)
54 if(libType
==UCLN_COMMON
) {
55 #if UCLN_DEBUG_CLEANUP
56 fprintf(stderr
, "Cleaning up: UCLN_COMMON with u_cleanup, type %d\n", (int)libType
);
60 #if UCLN_DEBUG_CLEANUP
61 fprintf(stderr
, "Cleaning up: using ucln_cleanup_internal, type %d\n", (int)libType
);
63 ucln_cleanup_internal(libType
);
69 ucln_common_registerCleanup(ECleanupCommonType type
,
72 U_ASSERT(UCLN_COMMON_START
< type
&& type
< UCLN_COMMON_COUNT
);
73 if (UCLN_COMMON_START
< type
&& type
< UCLN_COMMON_COUNT
)
75 gCommonCleanupFunctions
[type
] = func
;
77 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
78 ucln_registerAutomaticCleanup();
83 ucln_registerCleanup(ECleanupLibraryType type
,
86 U_ASSERT(UCLN_START
< type
&& type
< UCLN_COMMON
);
87 if (UCLN_START
< type
&& type
< UCLN_COMMON
)
89 gLibCleanupFunctions
[type
] = func
;
93 U_CFUNC UBool
ucln_lib_cleanup(void) {
94 ECleanupLibraryType libType
= UCLN_START
;
95 ECleanupCommonType commonFunc
= UCLN_COMMON_START
;
97 for (libType
++; libType
<UCLN_COMMON
; libType
++) {
98 ucln_cleanup_internal(libType
);
101 for (commonFunc
++; commonFunc
<UCLN_COMMON_COUNT
; commonFunc
++) {
102 if (gCommonCleanupFunctions
[commonFunc
])
104 gCommonCleanupFunctions
[commonFunc
]();
105 gCommonCleanupFunctions
[commonFunc
] = NULL
;
108 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
109 ucln_unRegisterAutomaticCleanup();