]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/uinit.c
ICU-6.2.4.tar.gz
[apple/icu.git] / icuSources / common / uinit.c
CommitLineData
374ca955
A
1/*
2******************************************************************************
3* *
4* Copyright (C) 2001-2004, 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/uclean.h"
19#include "utracimp.h"
20#include "ustr_imp.h"
21#include "unormimp.h"
22#include "ucln_cmn.h"
23#include "umutex.h"
24#include "ucln.h"
25#include "cmemory.h"
26#include "uassert.h"
27
28static UBool gICUInitialized = FALSE;
29static UMTX gICUInitMutex = NULL;
30
31
32static cleanupFunc *gLibCleanupFunctions[UCLN_COMMON];
33
34U_CAPI void U_EXPORT2
35ucln_registerCleanup(ECleanupLibraryType type,
36 cleanupFunc *func)
37{
38 U_ASSERT(UCLN_START < type && type < UCLN_COMMON);
39 if (UCLN_START < type && type < UCLN_COMMON)
40 {
41 gLibCleanupFunctions[type] = func;
42 }
43}
44
45/************************************************
46 The cleanup order is important in this function.
47 Please be sure that you have read ucln.h
48 ************************************************/
49U_CAPI void U_EXPORT2
50u_cleanup(void)
51{
52 ECleanupLibraryType libType;
53
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. */
57
58 for (libType = UCLN_START+1; libType<UCLN_COMMON; libType++) {
59 if (gLibCleanupFunctions[libType])
60 {
61 gLibCleanupFunctions[libType]();
62 gLibCleanupFunctions[libType] = NULL;
63 }
64 }
65
66 ucln_common_lib_cleanup();
67
68 umtx_destroy(&gICUInitMutex);
69 umtx_cleanup();
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. */
73 utrace_cleanup();
74}
75
76/*
77 *
78 * ICU Initialization Function. Force loading and/or initialization of
79 * any shared data that could potentially be used concurrently
80 * by multiple threads.
81 */
82U_CAPI void U_EXPORT2
83u_init(UErrorCode *status) {
84 UTRACE_ENTRY_OC(UTRACE_U_INIT);
85 /* Make sure the global mutexes are initialized. */
86 umtx_init(NULL);
87 umtx_lock(&gICUInitMutex);
88 if (gICUInitialized || U_FAILURE(*status)) {
89 umtx_unlock(&gICUInitMutex);
90 UTRACE_EXIT_STATUS(*status);
91 return;
92 }
93
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).
98 */
99
100 /* Char Properties */
101 uprv_loadPropsData(status);
102
103#if !UCONFIG_NO_NORMALIZATION
104 /* Normalization */
105 unorm_haveData(status);
106#endif
107 gICUInitialized = TRUE; /* TODO: don't set if U_FAILURE? */
108 umtx_unlock(&gICUInitMutex);
109 UTRACE_EXIT_STATUS(*status);
110}
111