]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/uinit.c
ICU-8.11.4.tar.gz
[apple/icu.git] / icuSources / common / uinit.c
CommitLineData
374ca955
A
1/*
2******************************************************************************
3* *
73c04bcf 4* Copyright (C) 2001-2006, International Business Machines *
374ca955
A
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/uclean.h"
19#include "utracimp.h"
20#include "ustr_imp.h"
21#include "unormimp.h"
22#include "ucln_cmn.h"
73c04bcf 23#include "ucnv_io.h"
374ca955
A
24#include "umutex.h"
25#include "ucln.h"
26#include "cmemory.h"
27#include "uassert.h"
28
29static UBool gICUInitialized = FALSE;
30static UMTX gICUInitMutex = NULL;
31
32
374ca955
A
33/************************************************
34 The cleanup order is important in this function.
35 Please be sure that you have read ucln.h
36 ************************************************/
37U_CAPI void U_EXPORT2
38u_cleanup(void)
39{
374ca955
A
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
73c04bcf 44 ucln_lib_cleanup();
374ca955
A
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. */
73c04bcf 51#if U_ENABLE_TRACING
374ca955 52 utrace_cleanup();
73c04bcf 53#endif
374ca955
A
54}
55
56/*
57 *
58 * ICU Initialization Function. Force loading and/or initialization of
59 * any shared data that could potentially be used concurrently
60 * by multiple threads.
61 */
62U_CAPI void U_EXPORT2
63u_init(UErrorCode *status) {
64 UTRACE_ENTRY_OC(UTRACE_U_INIT);
65 /* Make sure the global mutexes are initialized. */
66 umtx_init(NULL);
67 umtx_lock(&gICUInitMutex);
68 if (gICUInitialized || U_FAILURE(*status)) {
69 umtx_unlock(&gICUInitMutex);
70 UTRACE_EXIT_STATUS(*status);
71 return;
72 }
73
73c04bcf
A
74#if 1
75 /*
76 * 2005-may-02
77 *
78 * ICU4C 3.4 (jitterbug 4497) hardcodes the data for Unicode character
79 * properties for APIs that want to be fast.
80 * Therefore, we need not load them here nor check for errors.
81 * Instead, we load the converter alias table to see if any ICU data
82 * is available.
83 * Users should really open the service objects they need and check
84 * for errors there, to make sure that the actual items they need are
85 * available.
86 */
87#if !UCONFIG_NO_CONVERSION
88 ucnv_io_countTotalAliases(status);
89#endif
90#else
374ca955
A
91 /* Do any required init for services that don't have open operations
92 * and use "only" the double-check initialization method for performance
93 * reasons (avoiding a mutex lock even for _checking_ whether the
94 * initialization had occurred).
95 */
96
97 /* Char Properties */
73c04bcf
A
98 uprv_haveProperties(status);
99
100 /* load the case and bidi properties but don't fail if they are not available */
101 u_isULowercase(0x61);
102 u_getIntPropertyValue(0x200D, UCHAR_JOINING_TYPE); /* ZERO WIDTH JOINER: Join_Causing */
374ca955
A
103
104#if !UCONFIG_NO_NORMALIZATION
105 /* Normalization */
106 unorm_haveData(status);
73c04bcf 107#endif
374ca955
A
108#endif
109 gICUInitialized = TRUE; /* TODO: don't set if U_FAILURE? */
110 umtx_unlock(&gICUInitMutex);
111 UTRACE_EXIT_STATUS(*status);
112}
113