]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/unicode/uclean.h
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
20 #include "unicode/utypes.h"
23 * Initialize ICU. This function loads and initializes data items
24 * that are required internally by various ICU functions. Use of this explicit
25 * initialization is required in multi-threaded applications; in
26 * single threaded apps, use is optional, but incurs little additional
27 * cost, and is thus recommended.
29 * In multi-threaded applications, u_init() should be called in the
30 * main thread before starting additional threads, or, alternatively
31 * it can be called in each individual thread once, before other ICU
32 * functions are called in that thread. In this second scenario, the
33 * application must guarantee that the first call to u_init() happen
34 * without contention, in a single thread only.
36 * If <code>u_setMemoryFunctions()</code> or
37 * <code>u_setMutexFunctions</code> are needed (uncommon), they must be
38 * called _before_ <code>u_init()</code>.
40 * Extra, repeated, or otherwise unneeded calls to u_init() do no harm,
41 * other than taking a small amount of time.
43 * @param status An ICU UErrorCode parameter. It must not be <code>NULL</code>.
44 * An Error will be returned if some required part of ICU data can not
45 * be loaded or initialized.
46 * The function returns immediately if the input error code indicates a
51 U_STABLE
void U_EXPORT2
52 u_init(UErrorCode
*status
);
55 * Clean up the system resources, such as allocated memory or open files,
56 * used in all ICU libraries. This will free/delete all memory owned by the
57 * ICU libraries, and return them to their original load state. All open ICU
58 * items (collators, resource bundles, converters, etc.) must be closed before
59 * calling this function, otherwise ICU may not free its allocated memory
60 * (e.g. close your converters and resource bundles before calling this
61 * function). Generally, this function should be called once just before
62 * an application exits. For applications that dynamically load and unload
63 * the ICU libraries (relatively uncommon), u_cleanup() should be called
64 * just before the library unload.
66 * u_cleanup() also clears any ICU heap functions, mutex functions or
67 * trace functions that may have been set for the process.
68 * This has the effect of restoring ICU to its initial condition, before
69 * any of these override functions were installed. Refer to
70 * u_setMemoryFunctions(), u_setMutexFunctions and
71 * utrace_setFunctions(). If ICU is to be reinitialized after after
72 * calling u_cleanup(), these runtime override functions will need to
73 * be set up again if they are still required.
75 * u_cleanup() is not thread safe. All other threads should stop using ICU
76 * before calling this function.
78 * Any open ICU items will be left in an undefined state by u_cleanup(),
79 * and any subsequent attempt to use such an item will give unpredictable
82 * After calling u_cleanup(), an application may continue to use ICU by
83 * calling u_init(). An application must invoke u_init() first from one single
84 * thread before allowing other threads call u_init(). All threads existing
85 * at the time of the first thread's call to u_init() must also call
86 * u_init() themselves before continuing with other ICU operations.
88 * The use of u_cleanup() just before an application terminates is optional,
89 * but it should be called only once for performance reasons. The primary
90 * benefit is to eliminate reports of memory or resource leaks originating
91 * in ICU code from the results generated by heap analysis tools.
93 * <strong>Use this function with great care!</strong>
99 U_STABLE
void U_EXPORT2
106 * An opaque pointer type that represents an ICU mutex.
107 * For user-implemented mutexes, the value will typically point to a
108 * struct or object that implements the mutex.
115 * Function Pointer type for a user supplied mutex initialization function.
116 * The user-supplied function will be called by ICU whenever ICU needs to create a
117 * new mutex. The function implementation should create a mutex, and store a pointer
118 * to something that uniquely identifies the mutex into the UMTX that is supplied
120 * @param context user supplied value, obtained from from u_setMutexFunctions().
121 * @param mutex Receives a pointer that identifies the new mutex.
122 * The mutex init function must set the UMTX to a non-null value.
123 * Subsequent calls by ICU to lock, unlock, or destroy a mutex will
124 * identify the mutex by the UMTX value.
125 * @param status Error status. Report errors back to ICU by setting this variable
126 * with an error code.
130 typedef void U_CALLCONV
UMtxInitFn (const void *context
, UMTX
*mutex
, UErrorCode
* status
);
134 * Function Pointer type for a user supplied mutex functions.
135 * One of the user-supplied functions with this signature will be called by ICU
136 * whenever ICU needs to lock, unlock, or destroy a mutex.
137 * @param context user supplied value, obtained from from u_setMutexFunctions().
138 * @param mutex specify the mutex on which to operate.
142 typedef void U_CALLCONV
UMtxFn (const void *context
, UMTX
*mutex
);
146 * Set the functions that ICU will use for mutex operations
147 * Use of this function is optional; by default (without this function), ICU will
148 * directly access system functions for mutex operations
149 * This function can only be used when ICU is in an initial, unused state, before
150 * u_init() has been called.
151 * This function may be used even when ICU has been built without multi-threaded
152 * support (see ICU_USE_THREADS pre-processor variable, umutex.h)
153 * @param context This pointer value will be saved, and then (later) passed as
154 * a parameter to the user-supplied mutex functions each time they
156 * @param init Pointer to a mutex initialization function. Must be non-null.
157 * @param destroy Pointer to the mutex destroy function. Must be non-null.
158 * @param lock pointer to the mutex lock function. Must be non-null.
159 * @param unlock Pointer to the mutex unlock function. Must be non-null.
160 * @param status Receives error values.
164 U_DRAFT
void U_EXPORT2
165 u_setMutexFunctions(const void *context
, UMtxInitFn
*init
, UMtxFn
*destroy
, UMtxFn
*lock
, UMtxFn
*unlock
,
170 * Pointer type for a user supplied atomic increment or decrement function.
171 * @param context user supplied value, obtained from from u_setAtomicIncDecFunctions().
172 * @param p Pointer to a 32 bit int to be incremented or decremented
173 * @return The value of the variable after the inc or dec operation.
177 typedef int32_t U_CALLCONV
UMtxAtomicFn(const void *context
, int32_t *p
);
180 * Set the functions that ICU will use for atomic increment and decrement of int32_t values.
181 * Use of this function is optional; by default (without this function), ICU will
182 * use its own internal implementation of atomic increment/decrement.
183 * This function can only be used when ICU is in an initial, unused state, before
184 * u_init() has been called.
185 * @param context This pointer value will be saved, and then (later) passed as
186 * a parameter to the increment and decrement functions each time they
187 * are called. This function can only be called
188 * @param inc Pointer to a function to do an atomic increment operation. Must be non-null.
189 * @param dec Pointer to a function to do an atomic decrement operation. Must be non-null.
190 * @param status Receives error values.
194 U_DRAFT
void U_EXPORT2
195 u_setAtomicIncDecFunctions(const void *context
, UMtxAtomicFn
*inc
, UMtxAtomicFn
*dec
,
201 * Pointer type for a user supplied memory allocation function.
202 * @param context user supplied value, obtained from from u_setMemoryFunctions().
203 * @param size The number of bytes to be allocated
204 * @return Pointer to the newly allocated memory, or NULL if the allocation failed.
208 typedef void *U_CALLCONV
UMemAllocFn(const void *context
, size_t size
);
210 * Pointer type for a user supplied memory re-allocation function.
211 * @param context user supplied value, obtained from from u_setMemoryFunctions().
212 * @param size The number of bytes to be allocated
213 * @return Pointer to the newly allocated memory, or NULL if the allocation failed.
217 typedef void *U_CALLCONV
UMemReallocFn(const void *context
, void *mem
, size_t size
);
219 * Pointer type for a user supplied memory free function. Behavior should be
220 * similar the standard C library free().
221 * @param context user supplied value, obtained from from u_setMemoryFunctions().
222 * @param mem Pointer to the memory block to be resized
223 * @param size The new size for the block
224 * @return Pointer to the resized memory block, or NULL if the resizing failed.
228 typedef void U_CALLCONV
UMemFreeFn (const void *context
, void *mem
);
231 * Set the functions that ICU will use for memory allocation.
232 * Use of this function is optional; by default (without this function), ICU will
233 * use the standard C library malloc() and free() functions.
234 * This function can only be used when ICU is in an initial, unused state, before
235 * u_init() has been called.
236 * @param context This pointer value will be saved, and then (later) passed as
237 * a parameter to the memory functions each time they
239 * @param a Pointer to a user-supplied malloc function.
240 * @param r Pointer to a user-supplied realloc function.
241 * @param f Pointer to a user-supplied free function.
242 * @param status Receives error values.
246 U_DRAFT
void U_EXPORT2
247 u_setMemoryFunctions(const void *context
, UMemAllocFn
*a
, UMemReallocFn
*r
, UMemFreeFn
*f
,