xref: /aosp_15_r20/external/icu/libandroidicu/include/unicode/uclean.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2001-2014, International Business Machines
6*0e209d39SAndroid Build Coastguard Worker *                Corporation and others. All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
8*0e209d39SAndroid Build Coastguard Worker *   file name:  uclean.h
9*0e209d39SAndroid Build Coastguard Worker *   encoding:   UTF-8
10*0e209d39SAndroid Build Coastguard Worker *   tab size:   8 (not used)
11*0e209d39SAndroid Build Coastguard Worker *   indentation:4
12*0e209d39SAndroid Build Coastguard Worker *
13*0e209d39SAndroid Build Coastguard Worker *   created on: 2001July05
14*0e209d39SAndroid Build Coastguard Worker *   created by: George Rhoten
15*0e209d39SAndroid Build Coastguard Worker */
16*0e209d39SAndroid Build Coastguard Worker 
17*0e209d39SAndroid Build Coastguard Worker #ifndef __UCLEAN_H__
18*0e209d39SAndroid Build Coastguard Worker #define __UCLEAN_H__
19*0e209d39SAndroid Build Coastguard Worker 
20*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
21*0e209d39SAndroid Build Coastguard Worker /**
22*0e209d39SAndroid Build Coastguard Worker  * \file
23*0e209d39SAndroid Build Coastguard Worker  * \brief C API: Initialize and clean up ICU
24*0e209d39SAndroid Build Coastguard Worker  */
25*0e209d39SAndroid Build Coastguard Worker 
26*0e209d39SAndroid Build Coastguard Worker /**
27*0e209d39SAndroid Build Coastguard Worker  *  Initialize ICU.
28*0e209d39SAndroid Build Coastguard Worker  *
29*0e209d39SAndroid Build Coastguard Worker  *  Use of this function is optional.  It is OK to simply use ICU
30*0e209d39SAndroid Build Coastguard Worker  *  services and functions without first having initialized
31*0e209d39SAndroid Build Coastguard Worker  *  ICU by calling u_init().
32*0e209d39SAndroid Build Coastguard Worker  *
33*0e209d39SAndroid Build Coastguard Worker  *  u_init() will attempt to load some part of ICU's data, and is
34*0e209d39SAndroid Build Coastguard Worker  *  useful as a test for configuration or installation problems that
35*0e209d39SAndroid Build Coastguard Worker  *  leave the ICU data inaccessible.  A successful invocation of u_init()
36*0e209d39SAndroid Build Coastguard Worker  *  does not, however, guarantee that all ICU data is accessible.
37*0e209d39SAndroid Build Coastguard Worker  *
38*0e209d39SAndroid Build Coastguard Worker  *  Multiple calls to u_init() cause no harm, aside from the small amount
39*0e209d39SAndroid Build Coastguard Worker  *  of time required.
40*0e209d39SAndroid Build Coastguard Worker  *
41*0e209d39SAndroid Build Coastguard Worker  *  In old versions of ICU, u_init() was required in multi-threaded applications
42*0e209d39SAndroid Build Coastguard Worker  *  to ensure the thread safety of ICU.  u_init() is no longer needed for this purpose.
43*0e209d39SAndroid Build Coastguard Worker  *
44*0e209d39SAndroid Build Coastguard Worker  * @param status An ICU UErrorCode parameter. It must not be <code>NULL</code>.
45*0e209d39SAndroid Build Coastguard Worker  *    An Error will be returned if some required part of ICU data can not
46*0e209d39SAndroid Build Coastguard Worker  *    be loaded or initialized.
47*0e209d39SAndroid Build Coastguard Worker  *    The function returns immediately if the input error code indicates a
48*0e209d39SAndroid Build Coastguard Worker  *    failure, as usual.
49*0e209d39SAndroid Build Coastguard Worker  *
50*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.6
51*0e209d39SAndroid Build Coastguard Worker  */
52*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
53*0e209d39SAndroid Build Coastguard Worker u_init(UErrorCode *status);
54*0e209d39SAndroid Build Coastguard Worker 
55*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_SYSTEM_API
56*0e209d39SAndroid Build Coastguard Worker /**
57*0e209d39SAndroid Build Coastguard Worker  * Clean up the system resources, such as allocated memory or open files,
58*0e209d39SAndroid Build Coastguard Worker  * used in all ICU libraries. This will free/delete all memory owned by the
59*0e209d39SAndroid Build Coastguard Worker  * ICU libraries, and return them to their original load state. All open ICU
60*0e209d39SAndroid Build Coastguard Worker  * items (collators, resource bundles, converters, etc.) must be closed before
61*0e209d39SAndroid Build Coastguard Worker  * calling this function, otherwise ICU may not free its allocated memory
62*0e209d39SAndroid Build Coastguard Worker  * (e.g. close your converters and resource bundles before calling this
63*0e209d39SAndroid Build Coastguard Worker  * function). Generally, this function should be called once just before
64*0e209d39SAndroid Build Coastguard Worker  * an application exits. For applications that dynamically load and unload
65*0e209d39SAndroid Build Coastguard Worker  * the ICU libraries (relatively uncommon), u_cleanup() should be called
66*0e209d39SAndroid Build Coastguard Worker  * just before the library unload.
67*0e209d39SAndroid Build Coastguard Worker  * <p>
68*0e209d39SAndroid Build Coastguard Worker  * u_cleanup() also clears any ICU heap functions, mutex functions or
69*0e209d39SAndroid Build Coastguard Worker  * trace functions that may have been set for the process.
70*0e209d39SAndroid Build Coastguard Worker  * This has the effect of restoring ICU to its initial condition, before
71*0e209d39SAndroid Build Coastguard Worker  * any of these override functions were installed.  Refer to
72*0e209d39SAndroid Build Coastguard Worker  * u_setMemoryFunctions(), u_setMutexFunctions and
73*0e209d39SAndroid Build Coastguard Worker  * utrace_setFunctions().  If ICU is to be reinitialized after
74*0e209d39SAndroid Build Coastguard Worker  * calling u_cleanup(), these runtime override functions will need to
75*0e209d39SAndroid Build Coastguard Worker  * be set up again if they are still required.
76*0e209d39SAndroid Build Coastguard Worker  * <p>
77*0e209d39SAndroid Build Coastguard Worker  * u_cleanup() is not thread safe.  All other threads should stop using ICU
78*0e209d39SAndroid Build Coastguard Worker  * before calling this function.
79*0e209d39SAndroid Build Coastguard Worker  * <p>
80*0e209d39SAndroid Build Coastguard Worker  * Any open ICU items will be left in an undefined state by u_cleanup(),
81*0e209d39SAndroid Build Coastguard Worker  * and any subsequent attempt to use such an item will give unpredictable
82*0e209d39SAndroid Build Coastguard Worker  * results.
83*0e209d39SAndroid Build Coastguard Worker  * <p>
84*0e209d39SAndroid Build Coastguard Worker  * After calling u_cleanup(), an application may continue to use ICU by
85*0e209d39SAndroid Build Coastguard Worker  * calling u_init().  An application must invoke u_init() first from one single
86*0e209d39SAndroid Build Coastguard Worker  * thread before allowing other threads call u_init().  All threads existing
87*0e209d39SAndroid Build Coastguard Worker  * at the time of the first thread's call to u_init() must also call
88*0e209d39SAndroid Build Coastguard Worker  * u_init() themselves before continuing with other ICU operations.
89*0e209d39SAndroid Build Coastguard Worker  * <p>
90*0e209d39SAndroid Build Coastguard Worker  * The use of u_cleanup() just before an application terminates is optional,
91*0e209d39SAndroid Build Coastguard Worker  * but it should be called only once for performance reasons. The primary
92*0e209d39SAndroid Build Coastguard Worker  * benefit is to eliminate reports of memory or resource leaks originating
93*0e209d39SAndroid Build Coastguard Worker  * in ICU code from the results generated by heap analysis tools.
94*0e209d39SAndroid Build Coastguard Worker  * <p>
95*0e209d39SAndroid Build Coastguard Worker  * <strong>Use this function with great care!</strong>
96*0e209d39SAndroid Build Coastguard Worker  * </p>
97*0e209d39SAndroid Build Coastguard Worker  *
98*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
99*0e209d39SAndroid Build Coastguard Worker  * @system
100*0e209d39SAndroid Build Coastguard Worker  */
101*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
102*0e209d39SAndroid Build Coastguard Worker u_cleanup(void);
103*0e209d39SAndroid Build Coastguard Worker 
104*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN
105*0e209d39SAndroid Build Coastguard Worker /**
106*0e209d39SAndroid Build Coastguard Worker   *  Pointer type for a user supplied memory allocation function.
107*0e209d39SAndroid Build Coastguard Worker   *  @param context user supplied value, obtained from u_setMemoryFunctions().
108*0e209d39SAndroid Build Coastguard Worker   *  @param size    The number of bytes to be allocated
109*0e209d39SAndroid Build Coastguard Worker   *  @return        Pointer to the newly allocated memory, or NULL if the allocation failed.
110*0e209d39SAndroid Build Coastguard Worker   *  @stable ICU 2.8
111*0e209d39SAndroid Build Coastguard Worker   *  @system
112*0e209d39SAndroid Build Coastguard Worker   */
113*0e209d39SAndroid Build Coastguard Worker typedef void *U_CALLCONV UMemAllocFn(const void *context, size_t size);
114*0e209d39SAndroid Build Coastguard Worker /**
115*0e209d39SAndroid Build Coastguard Worker   *  Pointer type for a user supplied memory re-allocation function.
116*0e209d39SAndroid Build Coastguard Worker   *  @param context user supplied value, obtained from u_setMemoryFunctions().
117*0e209d39SAndroid Build Coastguard Worker   *  @param mem     Pointer to the memory block to be resized.
118*0e209d39SAndroid Build Coastguard Worker   *  @param size    The new size for the block.
119*0e209d39SAndroid Build Coastguard Worker   *  @return        Pointer to the newly allocated memory, or NULL if the allocation failed.
120*0e209d39SAndroid Build Coastguard Worker   *  @stable ICU 2.8
121*0e209d39SAndroid Build Coastguard Worker   *  @system
122*0e209d39SAndroid Build Coastguard Worker   */
123*0e209d39SAndroid Build Coastguard Worker typedef void *U_CALLCONV UMemReallocFn(const void *context, void *mem, size_t size);
124*0e209d39SAndroid Build Coastguard Worker /**
125*0e209d39SAndroid Build Coastguard Worker   *  Pointer type for a user supplied memory free  function.  Behavior should be
126*0e209d39SAndroid Build Coastguard Worker   *  similar the standard C library free().
127*0e209d39SAndroid Build Coastguard Worker   *  @param context user supplied value, obtained from u_setMemoryFunctions().
128*0e209d39SAndroid Build Coastguard Worker   *  @param mem     Pointer to the memory block to be freed.
129*0e209d39SAndroid Build Coastguard Worker   *  @return        Pointer to the resized memory block, or NULL if the resizing failed.
130*0e209d39SAndroid Build Coastguard Worker   *  @stable ICU 2.8
131*0e209d39SAndroid Build Coastguard Worker   *  @system
132*0e209d39SAndroid Build Coastguard Worker   */
133*0e209d39SAndroid Build Coastguard Worker typedef void  U_CALLCONV UMemFreeFn (const void *context, void *mem);
134*0e209d39SAndroid Build Coastguard Worker 
135*0e209d39SAndroid Build Coastguard Worker /**
136*0e209d39SAndroid Build Coastguard Worker  *  Set the functions that ICU will use for memory allocation.
137*0e209d39SAndroid Build Coastguard Worker  *  Use of this function is optional; by default (without this function), ICU will
138*0e209d39SAndroid Build Coastguard Worker  *  use the standard C library malloc() and free() functions.
139*0e209d39SAndroid Build Coastguard Worker  *  This function can only be used when ICU is in an initial, unused state, before
140*0e209d39SAndroid Build Coastguard Worker  *  u_init() has been called.
141*0e209d39SAndroid Build Coastguard Worker  *  @param context This pointer value will be saved, and then (later) passed as
142*0e209d39SAndroid Build Coastguard Worker  *                 a parameter to the memory functions each time they
143*0e209d39SAndroid Build Coastguard Worker  *                 are called.
144*0e209d39SAndroid Build Coastguard Worker  *  @param a       Pointer to a user-supplied malloc function.
145*0e209d39SAndroid Build Coastguard Worker  *  @param r       Pointer to a user-supplied realloc function.
146*0e209d39SAndroid Build Coastguard Worker  *  @param f       Pointer to a user-supplied free function.
147*0e209d39SAndroid Build Coastguard Worker  *  @param status  Receives error values.
148*0e209d39SAndroid Build Coastguard Worker  *  @stable ICU 2.8
149*0e209d39SAndroid Build Coastguard Worker  *  @system
150*0e209d39SAndroid Build Coastguard Worker  */
151*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
152*0e209d39SAndroid Build Coastguard Worker u_setMemoryFunctions(const void *context, UMemAllocFn * U_CALLCONV_FPTR a, UMemReallocFn * U_CALLCONV_FPTR r, UMemFreeFn * U_CALLCONV_FPTR f,
153*0e209d39SAndroid Build Coastguard Worker                     UErrorCode *status);
154*0e209d39SAndroid Build Coastguard Worker 
155*0e209d39SAndroid Build Coastguard Worker U_CDECL_END
156*0e209d39SAndroid Build Coastguard Worker 
157*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
158*0e209d39SAndroid Build Coastguard Worker /*********************************************************************************
159*0e209d39SAndroid Build Coastguard Worker  *
160*0e209d39SAndroid Build Coastguard Worker  * Deprecated Functions
161*0e209d39SAndroid Build Coastguard Worker  *
162*0e209d39SAndroid Build Coastguard Worker  *    The following functions for user supplied mutexes are no longer supported.
163*0e209d39SAndroid Build Coastguard Worker  *    Any attempt to use them will return a U_UNSUPPORTED_ERROR.
164*0e209d39SAndroid Build Coastguard Worker  *
165*0e209d39SAndroid Build Coastguard Worker  **********************************************************************************/
166*0e209d39SAndroid Build Coastguard Worker 
167*0e209d39SAndroid Build Coastguard Worker /**
168*0e209d39SAndroid Build Coastguard Worker   * An opaque pointer type that represents an ICU mutex.
169*0e209d39SAndroid Build Coastguard Worker   * For user-implemented mutexes, the value will typically point to a
170*0e209d39SAndroid Build Coastguard Worker   *  struct or object that implements the mutex.
171*0e209d39SAndroid Build Coastguard Worker   * @deprecated ICU 52. This type is no longer supported.
172*0e209d39SAndroid Build Coastguard Worker   * @system
173*0e209d39SAndroid Build Coastguard Worker   */
174*0e209d39SAndroid Build Coastguard Worker typedef void *UMTX;
175*0e209d39SAndroid Build Coastguard Worker 
176*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN
177*0e209d39SAndroid Build Coastguard Worker /**
178*0e209d39SAndroid Build Coastguard Worker   *  Function Pointer type for a user supplied mutex initialization function.
179*0e209d39SAndroid Build Coastguard Worker   *  The user-supplied function will be called by ICU whenever ICU needs to create a
180*0e209d39SAndroid Build Coastguard Worker   *  new mutex.  The function implementation should create a mutex, and store a pointer
181*0e209d39SAndroid Build Coastguard Worker   *  to something that uniquely identifies the mutex into the UMTX that is supplied
182*0e209d39SAndroid Build Coastguard Worker   *  as a parameter.
183*0e209d39SAndroid Build Coastguard Worker   *  @param context user supplied value, obtained from u_setMutexFunctions().
184*0e209d39SAndroid Build Coastguard Worker   *  @param mutex   Receives a pointer that identifies the new mutex.
185*0e209d39SAndroid Build Coastguard Worker   *                 The mutex init function must set the UMTX to a non-null value.
186*0e209d39SAndroid Build Coastguard Worker   *                 Subsequent calls by ICU to lock, unlock, or destroy a mutex will
187*0e209d39SAndroid Build Coastguard Worker   *                 identify the mutex by the UMTX value.
188*0e209d39SAndroid Build Coastguard Worker   *  @param status  Error status.  Report errors back to ICU by setting this variable
189*0e209d39SAndroid Build Coastguard Worker   *                 with an error code.
190*0e209d39SAndroid Build Coastguard Worker   *  @deprecated ICU 52. This function is no longer supported.
191*0e209d39SAndroid Build Coastguard Worker   *  @system
192*0e209d39SAndroid Build Coastguard Worker   */
193*0e209d39SAndroid Build Coastguard Worker typedef void U_CALLCONV UMtxInitFn (const void *context, UMTX  *mutex, UErrorCode* status);
194*0e209d39SAndroid Build Coastguard Worker 
195*0e209d39SAndroid Build Coastguard Worker 
196*0e209d39SAndroid Build Coastguard Worker /**
197*0e209d39SAndroid Build Coastguard Worker   *  Function Pointer type for a user supplied mutex functions.
198*0e209d39SAndroid Build Coastguard Worker   *  One of the  user-supplied functions with this signature will be called by ICU
199*0e209d39SAndroid Build Coastguard Worker   *  whenever ICU needs to lock, unlock, or destroy a mutex.
200*0e209d39SAndroid Build Coastguard Worker   *  @param context user supplied value, obtained from u_setMutexFunctions().
201*0e209d39SAndroid Build Coastguard Worker   *  @param mutex   specify the mutex on which to operate.
202*0e209d39SAndroid Build Coastguard Worker   *  @deprecated ICU 52. This function is no longer supported.
203*0e209d39SAndroid Build Coastguard Worker   *  @system
204*0e209d39SAndroid Build Coastguard Worker   */
205*0e209d39SAndroid Build Coastguard Worker typedef void U_CALLCONV UMtxFn   (const void *context, UMTX  *mutex);
206*0e209d39SAndroid Build Coastguard Worker U_CDECL_END
207*0e209d39SAndroid Build Coastguard Worker 
208*0e209d39SAndroid Build Coastguard Worker /**
209*0e209d39SAndroid Build Coastguard Worker   *  Set the functions that ICU will use for mutex operations
210*0e209d39SAndroid Build Coastguard Worker   *  Use of this function is optional; by default (without this function), ICU will
211*0e209d39SAndroid Build Coastguard Worker   *  directly access system functions for mutex operations
212*0e209d39SAndroid Build Coastguard Worker   *  This function can only be used when ICU is in an initial, unused state, before
213*0e209d39SAndroid Build Coastguard Worker   *  u_init() has been called.
214*0e209d39SAndroid Build Coastguard Worker   *  @param context This pointer value will be saved, and then (later) passed as
215*0e209d39SAndroid Build Coastguard Worker   *                 a parameter to the user-supplied mutex functions each time they
216*0e209d39SAndroid Build Coastguard Worker   *                 are called.
217*0e209d39SAndroid Build Coastguard Worker   *  @param init    Pointer to a mutex initialization function.  Must be non-null.
218*0e209d39SAndroid Build Coastguard Worker   *  @param destroy Pointer to the mutex destroy function.  Must be non-null.
219*0e209d39SAndroid Build Coastguard Worker   *  @param lock    pointer to the mutex lock function.  Must be non-null.
220*0e209d39SAndroid Build Coastguard Worker   *  @param unlock  Pointer to the mutex unlock function.  Must be non-null.
221*0e209d39SAndroid Build Coastguard Worker   *  @param status  Receives error values.
222*0e209d39SAndroid Build Coastguard Worker   *  @deprecated ICU 52. This function is no longer supported.
223*0e209d39SAndroid Build Coastguard Worker   *  @system
224*0e209d39SAndroid Build Coastguard Worker   */
225*0e209d39SAndroid Build Coastguard Worker U_DEPRECATED void U_EXPORT2
226*0e209d39SAndroid Build Coastguard Worker u_setMutexFunctions(const void *context, UMtxInitFn *init, UMtxFn *destroy, UMtxFn *lock, UMtxFn *unlock,
227*0e209d39SAndroid Build Coastguard Worker                     UErrorCode *status);
228*0e209d39SAndroid Build Coastguard Worker 
229*0e209d39SAndroid Build Coastguard Worker 
230*0e209d39SAndroid Build Coastguard Worker /**
231*0e209d39SAndroid Build Coastguard Worker   *  Pointer type for a user supplied atomic increment or decrement function.
232*0e209d39SAndroid Build Coastguard Worker   *  @param context user supplied value, obtained from u_setAtomicIncDecFunctions().
233*0e209d39SAndroid Build Coastguard Worker   *  @param p   Pointer to a 32 bit int to be incremented or decremented
234*0e209d39SAndroid Build Coastguard Worker   *  @return    The value of the variable after the inc or dec operation.
235*0e209d39SAndroid Build Coastguard Worker   *  @deprecated ICU 52. This function is no longer supported.
236*0e209d39SAndroid Build Coastguard Worker   *  @system
237*0e209d39SAndroid Build Coastguard Worker   */
238*0e209d39SAndroid Build Coastguard Worker typedef int32_t U_CALLCONV UMtxAtomicFn(const void *context, int32_t *p);
239*0e209d39SAndroid Build Coastguard Worker 
240*0e209d39SAndroid Build Coastguard Worker /**
241*0e209d39SAndroid Build Coastguard Worker  *  Set the functions that ICU will use for atomic increment and decrement of int32_t values.
242*0e209d39SAndroid Build Coastguard Worker  *  Use of this function is optional; by default (without this function), ICU will
243*0e209d39SAndroid Build Coastguard Worker  *  use its own internal implementation of atomic increment/decrement.
244*0e209d39SAndroid Build Coastguard Worker  *  This function can only be used when ICU is in an initial, unused state, before
245*0e209d39SAndroid Build Coastguard Worker  *  u_init() has been called.
246*0e209d39SAndroid Build Coastguard Worker  *  @param context This pointer value will be saved, and then (later) passed as
247*0e209d39SAndroid Build Coastguard Worker  *                 a parameter to the increment and decrement functions each time they
248*0e209d39SAndroid Build Coastguard Worker  *                 are called.  This function can only be called
249*0e209d39SAndroid Build Coastguard Worker  *  @param inc     Pointer to a function to do an atomic increment operation.  Must be non-null.
250*0e209d39SAndroid Build Coastguard Worker  *  @param dec     Pointer to a function to do an atomic decrement operation.  Must be non-null.
251*0e209d39SAndroid Build Coastguard Worker  *  @param status  Receives error values.
252*0e209d39SAndroid Build Coastguard Worker  *  @deprecated ICU 52. This function is no longer supported.
253*0e209d39SAndroid Build Coastguard Worker  *  @system
254*0e209d39SAndroid Build Coastguard Worker  */
255*0e209d39SAndroid Build Coastguard Worker U_DEPRECATED void U_EXPORT2
256*0e209d39SAndroid Build Coastguard Worker u_setAtomicIncDecFunctions(const void *context, UMtxAtomicFn *inc, UMtxAtomicFn *dec,
257*0e209d39SAndroid Build Coastguard Worker                     UErrorCode *status);
258*0e209d39SAndroid Build Coastguard Worker 
259*0e209d39SAndroid Build Coastguard Worker #endif  /* U_HIDE_DEPRECATED_API */
260*0e209d39SAndroid Build Coastguard Worker #endif  /* U_HIDE_SYSTEM_API */
261*0e209d39SAndroid Build Coastguard Worker 
262*0e209d39SAndroid Build Coastguard Worker #endif
263