jpayne@69: // © 2016 and later: Unicode, Inc. and others. jpayne@69: // License & terms of use: http://www.unicode.org/copyright.html jpayne@69: /* jpayne@69: ****************************************************************************** jpayne@69: * Copyright (C) 2001-2014, International Business Machines jpayne@69: * Corporation and others. All Rights Reserved. jpayne@69: ****************************************************************************** jpayne@69: * file name: uclean.h jpayne@69: * encoding: UTF-8 jpayne@69: * tab size: 8 (not used) jpayne@69: * indentation:4 jpayne@69: * jpayne@69: * created on: 2001July05 jpayne@69: * created by: George Rhoten jpayne@69: */ jpayne@69: jpayne@69: #ifndef __UCLEAN_H__ jpayne@69: #define __UCLEAN_H__ jpayne@69: jpayne@69: #include "unicode/utypes.h" jpayne@69: /** jpayne@69: * \file jpayne@69: * \brief C API: Initialize and clean up ICU jpayne@69: */ jpayne@69: jpayne@69: /** jpayne@69: * Initialize ICU. jpayne@69: * jpayne@69: * Use of this function is optional. It is OK to simply use ICU jpayne@69: * services and functions without first having initialized jpayne@69: * ICU by calling u_init(). jpayne@69: * jpayne@69: * u_init() will attempt to load some part of ICU's data, and is jpayne@69: * useful as a test for configuration or installation problems that jpayne@69: * leave the ICU data inaccessible. A successful invocation of u_init() jpayne@69: * does not, however, guarantee that all ICU data is accessible. jpayne@69: * jpayne@69: * Multiple calls to u_init() cause no harm, aside from the small amount jpayne@69: * of time required. jpayne@69: * jpayne@69: * In old versions of ICU, u_init() was required in multi-threaded applications jpayne@69: * to ensure the thread safety of ICU. u_init() is no longer needed for this purpose. jpayne@69: * jpayne@69: * @param status An ICU UErrorCode parameter. It must not be NULL. jpayne@69: * An Error will be returned if some required part of ICU data can not jpayne@69: * be loaded or initialized. jpayne@69: * The function returns immediately if the input error code indicates a jpayne@69: * failure, as usual. jpayne@69: * jpayne@69: * @stable ICU 2.6 jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: u_init(UErrorCode *status); jpayne@69: jpayne@69: #ifndef U_HIDE_SYSTEM_API jpayne@69: /** jpayne@69: * Clean up the system resources, such as allocated memory or open files, jpayne@69: * used in all ICU libraries. This will free/delete all memory owned by the jpayne@69: * ICU libraries, and return them to their original load state. All open ICU jpayne@69: * items (collators, resource bundles, converters, etc.) must be closed before jpayne@69: * calling this function, otherwise ICU may not free its allocated memory jpayne@69: * (e.g. close your converters and resource bundles before calling this jpayne@69: * function). Generally, this function should be called once just before jpayne@69: * an application exits. For applications that dynamically load and unload jpayne@69: * the ICU libraries (relatively uncommon), u_cleanup() should be called jpayne@69: * just before the library unload. jpayne@69: *

jpayne@69: * u_cleanup() also clears any ICU heap functions, mutex functions or jpayne@69: * trace functions that may have been set for the process. jpayne@69: * This has the effect of restoring ICU to its initial condition, before jpayne@69: * any of these override functions were installed. Refer to jpayne@69: * u_setMemoryFunctions(), u_setMutexFunctions and jpayne@69: * utrace_setFunctions(). If ICU is to be reinitialized after jpayne@69: * calling u_cleanup(), these runtime override functions will need to jpayne@69: * be set up again if they are still required. jpayne@69: *

jpayne@69: * u_cleanup() is not thread safe. All other threads should stop using ICU jpayne@69: * before calling this function. jpayne@69: *

jpayne@69: * Any open ICU items will be left in an undefined state by u_cleanup(), jpayne@69: * and any subsequent attempt to use such an item will give unpredictable jpayne@69: * results. jpayne@69: *

jpayne@69: * After calling u_cleanup(), an application may continue to use ICU by jpayne@69: * calling u_init(). An application must invoke u_init() first from one single jpayne@69: * thread before allowing other threads call u_init(). All threads existing jpayne@69: * at the time of the first thread's call to u_init() must also call jpayne@69: * u_init() themselves before continuing with other ICU operations. jpayne@69: *

jpayne@69: * The use of u_cleanup() just before an application terminates is optional, jpayne@69: * but it should be called only once for performance reasons. The primary jpayne@69: * benefit is to eliminate reports of memory or resource leaks originating jpayne@69: * in ICU code from the results generated by heap analysis tools. jpayne@69: *

jpayne@69: * Use this function with great care! jpayne@69: *

jpayne@69: * jpayne@69: * @stable ICU 2.0 jpayne@69: * @system jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: u_cleanup(void); jpayne@69: jpayne@69: U_CDECL_BEGIN jpayne@69: /** jpayne@69: * Pointer type for a user supplied memory allocation function. jpayne@69: * @param context user supplied value, obtained from u_setMemoryFunctions(). jpayne@69: * @param size The number of bytes to be allocated jpayne@69: * @return Pointer to the newly allocated memory, or NULL if the allocation failed. jpayne@69: * @stable ICU 2.8 jpayne@69: * @system jpayne@69: */ jpayne@69: typedef void *U_CALLCONV UMemAllocFn(const void *context, size_t size); jpayne@69: /** jpayne@69: * Pointer type for a user supplied memory re-allocation function. jpayne@69: * @param context user supplied value, obtained from u_setMemoryFunctions(). jpayne@69: * @param size The number of bytes to be allocated jpayne@69: * @return Pointer to the newly allocated memory, or NULL if the allocation failed. jpayne@69: * @stable ICU 2.8 jpayne@69: * @system jpayne@69: */ jpayne@69: typedef void *U_CALLCONV UMemReallocFn(const void *context, void *mem, size_t size); jpayne@69: /** jpayne@69: * Pointer type for a user supplied memory free function. Behavior should be jpayne@69: * similar the standard C library free(). jpayne@69: * @param context user supplied value, obtained from u_setMemoryFunctions(). jpayne@69: * @param mem Pointer to the memory block to be resized jpayne@69: * @param size The new size for the block jpayne@69: * @return Pointer to the resized memory block, or NULL if the resizing failed. jpayne@69: * @stable ICU 2.8 jpayne@69: * @system jpayne@69: */ jpayne@69: typedef void U_CALLCONV UMemFreeFn (const void *context, void *mem); jpayne@69: jpayne@69: /** jpayne@69: * Set the functions that ICU will use for memory allocation. jpayne@69: * Use of this function is optional; by default (without this function), ICU will jpayne@69: * use the standard C library malloc() and free() functions. jpayne@69: * This function can only be used when ICU is in an initial, unused state, before jpayne@69: * u_init() has been called. jpayne@69: * @param context This pointer value will be saved, and then (later) passed as jpayne@69: * a parameter to the memory functions each time they jpayne@69: * are called. jpayne@69: * @param a Pointer to a user-supplied malloc function. jpayne@69: * @param r Pointer to a user-supplied realloc function. jpayne@69: * @param f Pointer to a user-supplied free function. jpayne@69: * @param status Receives error values. jpayne@69: * @stable ICU 2.8 jpayne@69: * @system jpayne@69: */ jpayne@69: U_STABLE void U_EXPORT2 jpayne@69: u_setMemoryFunctions(const void *context, UMemAllocFn * U_CALLCONV_FPTR a, UMemReallocFn * U_CALLCONV_FPTR r, UMemFreeFn * U_CALLCONV_FPTR f, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: U_CDECL_END jpayne@69: jpayne@69: #ifndef U_HIDE_DEPRECATED_API jpayne@69: /********************************************************************************* jpayne@69: * jpayne@69: * Deprecated Functions jpayne@69: * jpayne@69: * The following functions for user supplied mutexes are no longer supported. jpayne@69: * Any attempt to use them will return a U_UNSUPPORTED_ERROR. jpayne@69: * jpayne@69: **********************************************************************************/ jpayne@69: jpayne@69: /** jpayne@69: * An opaque pointer type that represents an ICU mutex. jpayne@69: * For user-implemented mutexes, the value will typically point to a jpayne@69: * struct or object that implements the mutex. jpayne@69: * @deprecated ICU 52. This type is no longer supported. jpayne@69: * @system jpayne@69: */ jpayne@69: typedef void *UMTX; jpayne@69: jpayne@69: U_CDECL_BEGIN jpayne@69: /** jpayne@69: * Function Pointer type for a user supplied mutex initialization function. jpayne@69: * The user-supplied function will be called by ICU whenever ICU needs to create a jpayne@69: * new mutex. The function implementation should create a mutex, and store a pointer jpayne@69: * to something that uniquely identifies the mutex into the UMTX that is supplied jpayne@69: * as a parameter. jpayne@69: * @param context user supplied value, obtained from u_setMutexFunctions(). jpayne@69: * @param mutex Receives a pointer that identifies the new mutex. jpayne@69: * The mutex init function must set the UMTX to a non-null value. jpayne@69: * Subsequent calls by ICU to lock, unlock, or destroy a mutex will jpayne@69: * identify the mutex by the UMTX value. jpayne@69: * @param status Error status. Report errors back to ICU by setting this variable jpayne@69: * with an error code. jpayne@69: * @deprecated ICU 52. This function is no longer supported. jpayne@69: * @system jpayne@69: */ jpayne@69: typedef void U_CALLCONV UMtxInitFn (const void *context, UMTX *mutex, UErrorCode* status); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Function Pointer type for a user supplied mutex functions. jpayne@69: * One of the user-supplied functions with this signature will be called by ICU jpayne@69: * whenever ICU needs to lock, unlock, or destroy a mutex. jpayne@69: * @param context user supplied value, obtained from u_setMutexFunctions(). jpayne@69: * @param mutex specify the mutex on which to operate. jpayne@69: * @deprecated ICU 52. This function is no longer supported. jpayne@69: * @system jpayne@69: */ jpayne@69: typedef void U_CALLCONV UMtxFn (const void *context, UMTX *mutex); jpayne@69: U_CDECL_END jpayne@69: jpayne@69: /** jpayne@69: * Set the functions that ICU will use for mutex operations jpayne@69: * Use of this function is optional; by default (without this function), ICU will jpayne@69: * directly access system functions for mutex operations jpayne@69: * This function can only be used when ICU is in an initial, unused state, before jpayne@69: * u_init() has been called. jpayne@69: * @param context This pointer value will be saved, and then (later) passed as jpayne@69: * a parameter to the user-supplied mutex functions each time they jpayne@69: * are called. jpayne@69: * @param init Pointer to a mutex initialization function. Must be non-null. jpayne@69: * @param destroy Pointer to the mutex destroy function. Must be non-null. jpayne@69: * @param lock pointer to the mutex lock function. Must be non-null. jpayne@69: * @param unlock Pointer to the mutex unlock function. Must be non-null. jpayne@69: * @param status Receives error values. jpayne@69: * @deprecated ICU 52. This function is no longer supported. jpayne@69: * @system jpayne@69: */ jpayne@69: U_DEPRECATED void U_EXPORT2 jpayne@69: u_setMutexFunctions(const void *context, UMtxInitFn *init, UMtxFn *destroy, UMtxFn *lock, UMtxFn *unlock, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: jpayne@69: /** jpayne@69: * Pointer type for a user supplied atomic increment or decrement function. jpayne@69: * @param context user supplied value, obtained from u_setAtomicIncDecFunctions(). jpayne@69: * @param p Pointer to a 32 bit int to be incremented or decremented jpayne@69: * @return The value of the variable after the inc or dec operation. jpayne@69: * @deprecated ICU 52. This function is no longer supported. jpayne@69: * @system jpayne@69: */ jpayne@69: typedef int32_t U_CALLCONV UMtxAtomicFn(const void *context, int32_t *p); jpayne@69: jpayne@69: /** jpayne@69: * Set the functions that ICU will use for atomic increment and decrement of int32_t values. jpayne@69: * Use of this function is optional; by default (without this function), ICU will jpayne@69: * use its own internal implementation of atomic increment/decrement. jpayne@69: * This function can only be used when ICU is in an initial, unused state, before jpayne@69: * u_init() has been called. jpayne@69: * @param context This pointer value will be saved, and then (later) passed as jpayne@69: * a parameter to the increment and decrement functions each time they jpayne@69: * are called. This function can only be called jpayne@69: * @param inc Pointer to a function to do an atomic increment operation. Must be non-null. jpayne@69: * @param dec Pointer to a function to do an atomic decrement operation. Must be non-null. jpayne@69: * @param status Receives error values. jpayne@69: * @deprecated ICU 52. This function is no longer supported. jpayne@69: * @system jpayne@69: */ jpayne@69: U_DEPRECATED void U_EXPORT2 jpayne@69: u_setAtomicIncDecFunctions(const void *context, UMtxAtomicFn *inc, UMtxAtomicFn *dec, jpayne@69: UErrorCode *status); jpayne@69: jpayne@69: #endif /* U_HIDE_DEPRECATED_API */ jpayne@69: #endif /* U_HIDE_SYSTEM_API */ jpayne@69: jpayne@69: #endif