uclean.h 11 KB

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