]> git.saurik.com Git - apple/icu.git/blob - icuSources/common/uinit.c
ICU-461.13.tar.gz
[apple/icu.git] / icuSources / common / uinit.c
1 /*
2 ******************************************************************************
3 * *
4 * Copyright (C) 2001-2010, International Business Machines *
5 * Corporation and others. All Rights Reserved. *
6 * *
7 ******************************************************************************
8 * file name: uinit.c
9 * encoding: US-ASCII
10 * tab size: 8 (not used)
11 * indentation:4
12 *
13 * created on: 2001July05
14 * created by: George Rhoten
15 */
16
17 #include "unicode/utypes.h"
18 #include "unicode/icuplug.h"
19 #include "unicode/uclean.h"
20 #include "cmemory.h"
21 #include "icuplugimp.h"
22 #include "uassert.h"
23 #include "ucln.h"
24 #include "ucln_cmn.h"
25 #include "ucnv_io.h"
26 #include "umutex.h"
27 #include "utracimp.h"
28
29 static UBool gICUInitialized = FALSE;
30 static UMTX gICUInitMutex = NULL;
31
32
33 /************************************************
34 The cleanup order is important in this function.
35 Please be sure that you have read ucln.h
36 ************************************************/
37 U_CAPI void U_EXPORT2
38 u_cleanup(void)
39 {
40 UTRACE_ENTRY_OC(UTRACE_U_CLEANUP);
41 umtx_lock(NULL); /* Force a memory barrier, so that we are sure to see */
42 umtx_unlock(NULL); /* all state left around by any other threads. */
43
44 ucln_lib_cleanup();
45
46 umtx_destroy(&gICUInitMutex);
47 umtx_cleanup();
48 cmemory_cleanup(); /* undo any heap functions set by u_setMemoryFunctions(). */
49 gICUInitialized = FALSE;
50 UTRACE_EXIT(); /* Must be before utrace_cleanup(), which turns off tracing. */
51 /*#if U_ENABLE_TRACING*/
52 utrace_cleanup();
53 /*#endif*/
54 }
55
56 /*
57 * ICU Initialization Function. Need not be called.
58 */
59 U_CAPI void U_EXPORT2
60 u_init(UErrorCode *status) {
61 UTRACE_ENTRY_OC(UTRACE_U_INIT);
62 /* initialize plugins */
63 uplug_init(status);
64
65 umtx_lock(&gICUInitMutex);
66 if (gICUInitialized || U_FAILURE(*status)) {
67 umtx_unlock(&gICUInitMutex);
68 UTRACE_EXIT_STATUS(*status);
69 return;
70 }
71
72 /*
73 * 2005-may-02
74 *
75 * ICU4C 3.4 (jitterbug 4497) hardcodes the data for Unicode character
76 * properties for APIs that want to be fast.
77 * Therefore, we need not load them here nor check for errors.
78 * Instead, we load the converter alias table to see if any ICU data
79 * is available.
80 * Users should really open the service objects they need and check
81 * for errors there, to make sure that the actual items they need are
82 * available.
83 */
84 #if !UCONFIG_NO_CONVERSION
85 ucnv_io_countKnownConverters(status);
86 #endif
87
88 gICUInitialized = TRUE; /* TODO: don't set if U_FAILURE? */
89 umtx_unlock(&gICUInitMutex);
90 UTRACE_EXIT_STATUS(*status);
91 }