]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ****************************************************************************** | |
729e4ab9 A |
3 | * Copyright (C) 2001-2010, International Business Machines |
4 | * Corporation and others. All Rights Reserved. | |
b75a7d8f A |
5 | ****************************************************************************** |
6 | * file name: ucln_cmn.c | |
7 | * encoding: US-ASCII | |
8 | * tab size: 8 (not used) | |
9 | * indentation:4 | |
10 | * | |
11 | * created on: 2001July05 | |
12 | * created by: George Rhoten | |
13 | */ | |
14 | ||
15 | #include "unicode/utypes.h" | |
16 | #include "unicode/uclean.h" | |
374ca955 | 17 | #include "utracimp.h" |
b75a7d8f | 18 | #include "ustr_imp.h" |
b75a7d8f A |
19 | #include "ucln_cmn.h" |
20 | #include "umutex.h" | |
21 | #include "ucln.h" | |
374ca955 A |
22 | #include "cmemory.h" |
23 | #include "uassert.h" | |
b75a7d8f | 24 | |
729e4ab9 A |
25 | /** Auto-client for UCLN_COMMON **/ |
26 | #define UCLN_TYPE UCLN_COMMON | |
27 | #include "ucln_imp.h" | |
28 | ||
374ca955 | 29 | static cleanupFunc *gCommonCleanupFunctions[UCLN_COMMON_COUNT]; |
73c04bcf | 30 | static cleanupFunc *gLibCleanupFunctions[UCLN_COMMON]; |
b75a7d8f | 31 | |
729e4ab9 A |
32 | |
33 | /* Enables debugging information about when a library is cleaned up. */ | |
34 | #ifndef UCLN_DEBUG_CLEANUP | |
35 | #define UCLN_DEBUG_CLEANUP 0 | |
36 | #endif | |
37 | ||
38 | ||
39 | #if defined(UCLN_DEBUG_CLEANUP) | |
40 | #include <stdio.h> | |
41 | #endif | |
42 | ||
43 | static void ucln_cleanup_internal(ECleanupLibraryType libType) | |
44 | { | |
45 | if (gLibCleanupFunctions[libType]) | |
46 | { | |
47 | gLibCleanupFunctions[libType](); | |
48 | gLibCleanupFunctions[libType] = NULL; | |
49 | } | |
50 | } | |
51 | ||
52 | U_CAPI void U_EXPORT2 ucln_cleanupOne(ECleanupLibraryType libType) | |
53 | { | |
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); | |
57 | #endif | |
58 | u_cleanup(); | |
59 | } else { | |
60 | #if UCLN_DEBUG_CLEANUP | |
61 | fprintf(stderr, "Cleaning up: using ucln_cleanup_internal, type %d\n", (int)libType); | |
62 | #endif | |
63 | ucln_cleanup_internal(libType); | |
64 | } | |
65 | } | |
66 | ||
67 | ||
73c04bcf A |
68 | U_CFUNC void |
69 | ucln_common_registerCleanup(ECleanupCommonType type, | |
70 | cleanupFunc *func) | |
b75a7d8f | 71 | { |
374ca955 A |
72 | U_ASSERT(UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT); |
73 | if (UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT) | |
b75a7d8f | 74 | { |
374ca955 | 75 | gCommonCleanupFunctions[type] = func; |
b75a7d8f | 76 | } |
729e4ab9 A |
77 | #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL)) |
78 | ucln_registerAutomaticCleanup(); | |
79 | #endif | |
b75a7d8f A |
80 | } |
81 | ||
73c04bcf A |
82 | U_CAPI void U_EXPORT2 |
83 | ucln_registerCleanup(ECleanupLibraryType type, | |
84 | cleanupFunc *func) | |
85 | { | |
86 | U_ASSERT(UCLN_START < type && type < UCLN_COMMON); | |
87 | if (UCLN_START < type && type < UCLN_COMMON) | |
88 | { | |
89 | gLibCleanupFunctions[type] = func; | |
90 | } | |
91 | } | |
92 | ||
93 | U_CFUNC UBool ucln_lib_cleanup(void) { | |
94 | ECleanupLibraryType libType = UCLN_START; | |
95 | ECleanupCommonType commonFunc = UCLN_COMMON_START; | |
96 | ||
97 | for (libType++; libType<UCLN_COMMON; libType++) { | |
729e4ab9 | 98 | ucln_cleanup_internal(libType); |
73c04bcf | 99 | } |
b75a7d8f | 100 | |
73c04bcf | 101 | for (commonFunc++; commonFunc<UCLN_COMMON_COUNT; commonFunc++) { |
374ca955 | 102 | if (gCommonCleanupFunctions[commonFunc]) |
b75a7d8f | 103 | { |
374ca955 A |
104 | gCommonCleanupFunctions[commonFunc](); |
105 | gCommonCleanupFunctions[commonFunc] = NULL; | |
b75a7d8f | 106 | } |
b75a7d8f | 107 | } |
729e4ab9 A |
108 | #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL)) |
109 | ucln_unRegisterAutomaticCleanup(); | |
110 | #endif | |
374ca955 | 111 | return TRUE; |
b75a7d8f | 112 | } |