2 ******************************************************************************
4 * Copyright (C) 2001-2004, International Business Machines *
5 * Corporation and others. All Rights Reserved. *
7 ******************************************************************************
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"
28 static UBool gICUInitialized
= FALSE
;
29 static UMTX gICUInitMutex
= NULL
;
32 static cleanupFunc
*gLibCleanupFunctions
[UCLN_COMMON
];
35 ucln_registerCleanup(ECleanupLibraryType type
,
38 U_ASSERT(UCLN_START
< type
&& type
< UCLN_COMMON
);
39 if (UCLN_START
< type
&& type
< UCLN_COMMON
)
41 gLibCleanupFunctions
[type
] = func
;
45 /************************************************
46 The cleanup order is important in this function.
47 Please be sure that you have read ucln.h
48 ************************************************/
52 ECleanupLibraryType libType
;
54 UTRACE_ENTRY_OC(UTRACE_U_CLEANUP
);
55 umtx_lock(NULL
); /* Force a memory barrier, so that we are sure to see */
56 umtx_unlock(NULL
); /* all state left around by any other threads. */
58 for (libType
= UCLN_START
+1; libType
<UCLN_COMMON
; libType
++) {
59 if (gLibCleanupFunctions
[libType
])
61 gLibCleanupFunctions
[libType
]();
62 gLibCleanupFunctions
[libType
] = NULL
;
66 ucln_common_lib_cleanup();
68 umtx_destroy(&gICUInitMutex
);
70 cmemory_cleanup(); /* undo any heap functions set by u_setMemoryFunctions(). */
71 gICUInitialized
= FALSE
;
72 UTRACE_EXIT(); /* Must be before utrace_cleanup(), which turns off tracing. */
78 * ICU Initialization Function. Force loading and/or initialization of
79 * any shared data that could potentially be used concurrently
80 * by multiple threads.
83 u_init(UErrorCode
*status
) {
84 UTRACE_ENTRY_OC(UTRACE_U_INIT
);
85 /* Make sure the global mutexes are initialized. */
87 umtx_lock(&gICUInitMutex
);
88 if (gICUInitialized
|| U_FAILURE(*status
)) {
89 umtx_unlock(&gICUInitMutex
);
90 UTRACE_EXIT_STATUS(*status
);
94 /* Do any required init for services that don't have open operations
95 * and use "only" the double-check initialization method for performance
96 * reasons (avoiding a mutex lock even for _checking_ whether the
97 * initialization had occurred).
100 /* Char Properties */
101 uprv_loadPropsData(status
);
103 #if !UCONFIG_NO_NORMALIZATION
105 unorm_haveData(status
);
107 gICUInitialized
= TRUE
; /* TODO: don't set if U_FAILURE? */
108 umtx_unlock(&gICUInitMutex
);
109 UTRACE_EXIT_STATUS(*status
);