OLD | NEW |
1 /* | 1 /* |
2 ****************************************************************************** | 2 ****************************************************************************** |
3 * Copyright (C) 2001-2013, International Business Machines | 3 * Copyright (C) 2001-2014, International Business Machines |
4 * Corporation and others. All Rights Reserved. | 4 * Corporation and others. All Rights Reserved. |
5 ****************************************************************************** | 5 ****************************************************************************** |
6 * file name: ucln_cmn.c | 6 * file name: ucln_cmn.cpp |
7 * encoding: US-ASCII | 7 * encoding: US-ASCII |
8 * tab size: 8 (not used) | 8 * tab size: 8 (not used) |
9 * indentation:4 | 9 * indentation:4 |
10 * | 10 * |
11 * created on: 2001July05 | 11 * created on: 2001July05 |
12 * created by: George Rhoten | 12 * created by: George Rhoten |
13 */ | 13 */ |
14 | 14 |
15 #include "unicode/utypes.h" | 15 #include "unicode/utypes.h" |
16 #include "unicode/uclean.h" | 16 #include "unicode/uclean.h" |
| 17 #include "cmemory.h" |
| 18 #include "mutex.h" |
| 19 #include "uassert.h" |
| 20 #include "ucln.h" |
| 21 #include "ucln_cmn.h" |
17 #include "utracimp.h" | 22 #include "utracimp.h" |
18 #include "ucln_cmn.h" | 23 #include "umutex.h" |
19 #include "cmutex.h" | |
20 #include "ucln.h" | |
21 #include "cmemory.h" | |
22 #include "uassert.h" | |
23 | 24 |
24 /** Auto-client for UCLN_COMMON **/ | 25 /** Auto-client for UCLN_COMMON **/ |
25 #define UCLN_TYPE_IS_COMMON | 26 #define UCLN_TYPE_IS_COMMON |
26 #include "ucln_imp.h" | 27 #include "ucln_imp.h" |
27 | 28 |
28 static cleanupFunc *gCommonCleanupFunctions[UCLN_COMMON_COUNT]; | 29 static cleanupFunc *gCommonCleanupFunctions[UCLN_COMMON_COUNT]; |
29 static cleanupFunc *gLibCleanupFunctions[UCLN_COMMON]; | 30 static cleanupFunc *gLibCleanupFunctions[UCLN_COMMON]; |
30 | 31 |
31 | 32 |
32 /************************************************ | 33 /************************************************ |
(...skipping 25 matching lines...) Expand all Loading... |
58 } | 59 } |
59 } | 60 } |
60 | 61 |
61 U_CFUNC void | 62 U_CFUNC void |
62 ucln_common_registerCleanup(ECleanupCommonType type, | 63 ucln_common_registerCleanup(ECleanupCommonType type, |
63 cleanupFunc *func) | 64 cleanupFunc *func) |
64 { | 65 { |
65 U_ASSERT(UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT); | 66 U_ASSERT(UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT); |
66 if (UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT) | 67 if (UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT) |
67 { | 68 { |
| 69 icu::Mutex m; // See ticket 10295 for discussion. |
68 gCommonCleanupFunctions[type] = func; | 70 gCommonCleanupFunctions[type] = func; |
69 } | 71 } |
70 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOC
AL)) | 72 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOC
AL)) |
71 ucln_registerAutomaticCleanup(); | 73 ucln_registerAutomaticCleanup(); |
72 #endif | 74 #endif |
73 } | 75 } |
74 | 76 |
| 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. |
| 80 |
75 U_CAPI void U_EXPORT2 | 81 U_CAPI void U_EXPORT2 |
76 ucln_registerCleanup(ECleanupLibraryType type, | 82 ucln_registerCleanup(ECleanupLibraryType type, |
77 cleanupFunc *func) | 83 cleanupFunc *func) |
78 { | 84 { |
79 U_ASSERT(UCLN_START < type && type < UCLN_COMMON); | 85 U_ASSERT(UCLN_START < type && type < UCLN_COMMON); |
80 if (UCLN_START < type && type < UCLN_COMMON) | 86 if (UCLN_START < type && type < UCLN_COMMON) |
81 { | 87 { |
82 gLibCleanupFunctions[type] = func; | 88 gLibCleanupFunctions[type] = func; |
83 } | 89 } |
84 } | 90 } |
85 | 91 |
86 U_CFUNC UBool ucln_lib_cleanup(void) { | 92 U_CFUNC UBool ucln_lib_cleanup(void) { |
87 ECleanupLibraryType libType = UCLN_START; | 93 int32_t libType = UCLN_START; |
88 ECleanupCommonType commonFunc = UCLN_COMMON_START; | 94 int32_t commonFunc = UCLN_COMMON_START; |
89 | 95 |
90 for (libType++; libType<UCLN_COMMON; libType++) { | 96 for (libType++; libType<UCLN_COMMON; libType++) { |
91 ucln_cleanupOne(libType); | 97 ucln_cleanupOne(static_cast<ECleanupLibraryType>(libType)); |
92 } | 98 } |
93 | 99 |
94 for (commonFunc++; commonFunc<UCLN_COMMON_COUNT; commonFunc++) { | 100 for (commonFunc++; commonFunc<UCLN_COMMON_COUNT; commonFunc++) { |
95 if (gCommonCleanupFunctions[commonFunc]) | 101 if (gCommonCleanupFunctions[commonFunc]) |
96 { | 102 { |
97 gCommonCleanupFunctions[commonFunc](); | 103 gCommonCleanupFunctions[commonFunc](); |
98 gCommonCleanupFunctions[commonFunc] = NULL; | 104 gCommonCleanupFunctions[commonFunc] = NULL; |
99 } | 105 } |
100 } | 106 } |
101 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOC
AL)) | 107 #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOC
AL)) |
102 ucln_unRegisterAutomaticCleanup(); | 108 ucln_unRegisterAutomaticCleanup(); |
103 #endif | 109 #endif |
104 return TRUE; | 110 return TRUE; |
105 } | 111 } |
OLD | NEW |