uclean.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. // Copyright (C) 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: US-ASCII
  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_STABLE 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 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_STABLE void U_EXPORT2
  98. u_cleanup(void);
  99. /**
  100. * Pointer type for a user supplied memory allocation function.
  101. * @param context user supplied value, obtained from from u_setMemoryFunctions().
  102. * @param size The number of bytes to be allocated
  103. * @return Pointer to the newly allocated memory, or NULL if the allocation failed.
  104. * @stable ICU 2.8
  105. * @system
  106. */
  107. typedef void *U_CALLCONV UMemAllocFn(const void *context, size_t size);
  108. /**
  109. * Pointer type for a user supplied memory re-allocation function.
  110. * @param context user supplied value, obtained from from u_setMemoryFunctions().
  111. * @param size The number of bytes to be allocated
  112. * @return Pointer to the newly allocated memory, or NULL if the allocation failed.
  113. * @stable ICU 2.8
  114. * @system
  115. */
  116. typedef void *U_CALLCONV UMemReallocFn(const void *context, void *mem, size_t size);
  117. /**
  118. * Pointer type for a user supplied memory free function. Behavior should be
  119. * similar the standard C library free().
  120. * @param context user supplied value, obtained from from u_setMemoryFunctions().
  121. * @param mem Pointer to the memory block to be resized
  122. * @param size The new size for the block
  123. * @return Pointer to the resized memory block, or NULL if the resizing failed.
  124. * @stable ICU 2.8
  125. * @system
  126. */
  127. typedef void U_CALLCONV UMemFreeFn (const void *context, void *mem);
  128. /**
  129. * Set the functions that ICU will use for memory allocation.
  130. * Use of this function is optional; by default (without this function), ICU will
  131. * use the standard C library malloc() and free() functions.
  132. * This function can only be used when ICU is in an initial, unused state, before
  133. * u_init() has been called.
  134. * @param context This pointer value will be saved, and then (later) passed as
  135. * a parameter to the memory functions each time they
  136. * are called.
  137. * @param a Pointer to a user-supplied malloc function.
  138. * @param r Pointer to a user-supplied realloc function.
  139. * @param f Pointer to a user-supplied free function.
  140. * @param status Receives error values.
  141. * @stable ICU 2.8
  142. * @system
  143. */
  144. U_STABLE void U_EXPORT2
  145. u_setMemoryFunctions(const void *context, UMemAllocFn *a, UMemReallocFn *r, UMemFreeFn *f,
  146. UErrorCode *status);
  147. #ifndef U_HIDE_DEPRECATED_API
  148. /*********************************************************************************
  149. *
  150. * Deprecated Functions
  151. *
  152. * The following functions for user supplied mutexes are no longer supported.
  153. * Any attempt to use them will return a U_UNSUPPORTED_ERROR.
  154. *
  155. **********************************************************************************/
  156. /**
  157. * An opaque pointer type that represents an ICU mutex.
  158. * For user-implemented mutexes, the value will typically point to a
  159. * struct or object that implements the mutex.
  160. * @deprecated ICU 52. This type is no longer supported.
  161. * @system
  162. */
  163. typedef void *UMTX;
  164. /**
  165. * Function Pointer type for a user supplied mutex initialization function.
  166. * The user-supplied function will be called by ICU whenever ICU needs to create a
  167. * new mutex. The function implementation should create a mutex, and store a pointer
  168. * to something that uniquely identifies the mutex into the UMTX that is supplied
  169. * as a paramter.
  170. * @param context user supplied value, obtained from from u_setMutexFunctions().
  171. * @param mutex Receives a pointer that identifies the new mutex.
  172. * The mutex init function must set the UMTX to a non-null value.
  173. * Subsequent calls by ICU to lock, unlock, or destroy a mutex will
  174. * identify the mutex by the UMTX value.
  175. * @param status Error status. Report errors back to ICU by setting this variable
  176. * with an error code.
  177. * @deprecated ICU 52. This function is no longer supported.
  178. * @system
  179. */
  180. typedef void U_CALLCONV UMtxInitFn (const void *context, UMTX *mutex, UErrorCode* status);
  181. /**
  182. * Function Pointer type for a user supplied mutex functions.
  183. * One of the user-supplied functions with this signature will be called by ICU
  184. * whenever ICU needs to lock, unlock, or destroy a mutex.
  185. * @param context user supplied value, obtained from from u_setMutexFunctions().
  186. * @param mutex specify the mutex on which to operate.
  187. * @deprecated ICU 52. This function is no longer supported.
  188. * @system
  189. */
  190. typedef void U_CALLCONV UMtxFn (const void *context, UMTX *mutex);
  191. /**
  192. * Set the functions that ICU will use for mutex operations
  193. * Use of this function is optional; by default (without this function), ICU will
  194. * directly access system functions for mutex operations
  195. * This function can only be used when ICU is in an initial, unused state, before
  196. * u_init() has been called.
  197. * @param context This pointer value will be saved, and then (later) passed as
  198. * a parameter to the user-supplied mutex functions each time they
  199. * are called.
  200. * @param init Pointer to a mutex initialization function. Must be non-null.
  201. * @param destroy Pointer to the mutex destroy function. Must be non-null.
  202. * @param lock pointer to the mutex lock function. Must be non-null.
  203. * @param unlock Pointer to the mutex unlock function. Must be non-null.
  204. * @param status Receives error values.
  205. * @deprecated ICU 52. This function is no longer supported.
  206. * @system
  207. */
  208. U_DEPRECATED void U_EXPORT2
  209. u_setMutexFunctions(const void *context, UMtxInitFn *init, UMtxFn *destroy, UMtxFn *lock, UMtxFn *unlock,
  210. UErrorCode *status);
  211. /**
  212. * Pointer type for a user supplied atomic increment or decrement function.
  213. * @param context user supplied value, obtained from from u_setAtomicIncDecFunctions().
  214. * @param p Pointer to a 32 bit int to be incremented or decremented
  215. * @return The value of the variable after the inc or dec operation.
  216. * @deprecated ICU 52. This function is no longer supported.
  217. * @system
  218. */
  219. typedef int32_t U_CALLCONV UMtxAtomicFn(const void *context, int32_t *p);
  220. /**
  221. * Set the functions that ICU will use for atomic increment and decrement of int32_t values.
  222. * Use of this function is optional; by default (without this function), ICU will
  223. * use its own internal implementation of atomic increment/decrement.
  224. * This function can only be used when ICU is in an initial, unused state, before
  225. * u_init() has been called.
  226. * @param context This pointer value will be saved, and then (later) passed as
  227. * a parameter to the increment and decrement functions each time they
  228. * are called. This function can only be called
  229. * @param inc Pointer to a function to do an atomic increment operation. Must be non-null.
  230. * @param dec Pointer to a function to do an atomic decrement operation. Must be non-null.
  231. * @param status Receives error values.
  232. * @deprecated ICU 52. This function is no longer supported.
  233. * @system
  234. */
  235. U_DEPRECATED void U_EXPORT2
  236. u_setAtomicIncDecFunctions(const void *context, UMtxAtomicFn *inc, UMtxAtomicFn *dec,
  237. UErrorCode *status);
  238. #endif /* U_HIDE_DEPRECATED_API */
  239. #endif /* U_HIDE_SYSTEM_API */
  240. #endif