uclean.h 11 KB

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