michael@0: /*
michael@0: ******************************************************************************
michael@0: * Copyright (C) 2001-2013, International Business Machines
michael@0: * Corporation and others. All Rights Reserved.
michael@0: ******************************************************************************
michael@0: * file name: uclean.h
michael@0: * encoding: US-ASCII
michael@0: * tab size: 8 (not used)
michael@0: * indentation:4
michael@0: *
michael@0: * created on: 2001July05
michael@0: * created by: George Rhoten
michael@0: */
michael@0:
michael@0: #ifndef __UCLEAN_H__
michael@0: #define __UCLEAN_H__
michael@0:
michael@0: #include "unicode/utypes.h"
michael@0: /**
michael@0: * \file
michael@0: * \brief C API: Initialize and clean up ICU
michael@0: */
michael@0:
michael@0: /**
michael@0: * Initialize ICU.
michael@0: *
michael@0: * Use of this function is optional. It is OK to simply use ICU
michael@0: * services and functions without first having initialized
michael@0: * ICU by calling u_init().
michael@0: *
michael@0: * u_init() will attempt to load some part of ICU's data, and is
michael@0: * useful as a test for configuration or installation problems that
michael@0: * leave the ICU data inaccessible. A successful invocation of u_init()
michael@0: * does not, however, guarantee that all ICU data is accessible.
michael@0: *
michael@0: * Multiple calls to u_init() cause no harm, aside from the small amount
michael@0: * of time required.
michael@0: *
michael@0: * In old versions of ICU, u_init() was required in multi-threaded applications
michael@0: * to ensure the thread safety of ICU. u_init() is no longer needed for this purpose.
michael@0: *
michael@0: * @param status An ICU UErrorCode parameter. It must not be NULL
.
michael@0: * An Error will be returned if some required part of ICU data can not
michael@0: * be loaded or initialized.
michael@0: * The function returns immediately if the input error code indicates a
michael@0: * failure, as usual.
michael@0: *
michael@0: * @stable ICU 2.6
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: u_init(UErrorCode *status);
michael@0:
michael@0: #ifndef U_HIDE_SYSTEM_API
michael@0: /**
michael@0: * Clean up the system resources, such as allocated memory or open files,
michael@0: * used in all ICU libraries. This will free/delete all memory owned by the
michael@0: * ICU libraries, and return them to their original load state. All open ICU
michael@0: * items (collators, resource bundles, converters, etc.) must be closed before
michael@0: * calling this function, otherwise ICU may not free its allocated memory
michael@0: * (e.g. close your converters and resource bundles before calling this
michael@0: * function). Generally, this function should be called once just before
michael@0: * an application exits. For applications that dynamically load and unload
michael@0: * the ICU libraries (relatively uncommon), u_cleanup() should be called
michael@0: * just before the library unload.
michael@0: *
michael@0: * u_cleanup() also clears any ICU heap functions, mutex functions or michael@0: * trace functions that may have been set for the process. michael@0: * This has the effect of restoring ICU to its initial condition, before michael@0: * any of these override functions were installed. Refer to michael@0: * u_setMemoryFunctions(), u_setMutexFunctions and michael@0: * utrace_setFunctions(). If ICU is to be reinitialized after after michael@0: * calling u_cleanup(), these runtime override functions will need to michael@0: * be set up again if they are still required. michael@0: *
michael@0: * u_cleanup() is not thread safe. All other threads should stop using ICU michael@0: * before calling this function. michael@0: *
michael@0: * Any open ICU items will be left in an undefined state by u_cleanup(), michael@0: * and any subsequent attempt to use such an item will give unpredictable michael@0: * results. michael@0: *
michael@0: * After calling u_cleanup(), an application may continue to use ICU by michael@0: * calling u_init(). An application must invoke u_init() first from one single michael@0: * thread before allowing other threads call u_init(). All threads existing michael@0: * at the time of the first thread's call to u_init() must also call michael@0: * u_init() themselves before continuing with other ICU operations. michael@0: *
michael@0: * The use of u_cleanup() just before an application terminates is optional, michael@0: * but it should be called only once for performance reasons. The primary michael@0: * benefit is to eliminate reports of memory or resource leaks originating michael@0: * in ICU code from the results generated by heap analysis tools. michael@0: *
michael@0: * Use this function with great care! michael@0: *
michael@0: * michael@0: * @stable ICU 2.0 michael@0: * @system michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: u_cleanup(void); michael@0: michael@0: michael@0: /** michael@0: * Pointer type for a user supplied memory allocation function. michael@0: * @param context user supplied value, obtained from from u_setMemoryFunctions(). michael@0: * @param size The number of bytes to be allocated michael@0: * @return Pointer to the newly allocated memory, or NULL if the allocation failed. michael@0: * @stable ICU 2.8 michael@0: * @system michael@0: */ michael@0: typedef void *U_CALLCONV UMemAllocFn(const void *context, size_t size); michael@0: /** michael@0: * Pointer type for a user supplied memory re-allocation function. michael@0: * @param context user supplied value, obtained from from u_setMemoryFunctions(). michael@0: * @param size The number of bytes to be allocated michael@0: * @return Pointer to the newly allocated memory, or NULL if the allocation failed. michael@0: * @stable ICU 2.8 michael@0: * @system michael@0: */ michael@0: typedef void *U_CALLCONV UMemReallocFn(const void *context, void *mem, size_t size); michael@0: /** michael@0: * Pointer type for a user supplied memory free function. Behavior should be michael@0: * similar the standard C library free(). michael@0: * @param context user supplied value, obtained from from u_setMemoryFunctions(). michael@0: * @param mem Pointer to the memory block to be resized michael@0: * @param size The new size for the block michael@0: * @return Pointer to the resized memory block, or NULL if the resizing failed. michael@0: * @stable ICU 2.8 michael@0: * @system michael@0: */ michael@0: typedef void U_CALLCONV UMemFreeFn (const void *context, void *mem); michael@0: michael@0: /** michael@0: * Set the functions that ICU will use for memory allocation. michael@0: * Use of this function is optional; by default (without this function), ICU will michael@0: * use the standard C library malloc() and free() functions. michael@0: * This function can only be used when ICU is in an initial, unused state, before michael@0: * u_init() has been called. michael@0: * @param context This pointer value will be saved, and then (later) passed as michael@0: * a parameter to the memory functions each time they michael@0: * are called. michael@0: * @param a Pointer to a user-supplied malloc function. michael@0: * @param r Pointer to a user-supplied realloc function. michael@0: * @param f Pointer to a user-supplied free function. michael@0: * @param status Receives error values. michael@0: * @stable ICU 2.8 michael@0: * @system michael@0: */ michael@0: U_STABLE void U_EXPORT2 michael@0: u_setMemoryFunctions(const void *context, UMemAllocFn *a, UMemReallocFn *r, UMemFreeFn *f, michael@0: UErrorCode *status); michael@0: michael@0: michael@0: /********************************************************************************* michael@0: * michael@0: * Deprecated Functions michael@0: * michael@0: * The following functions for user supplied mutexes are no longer supported. michael@0: * Any attempt to use them will return a U_UNSUPPORTED_ERROR. michael@0: * michael@0: **********************************************************************************/ michael@0: michael@0: /** michael@0: * An opaque pointer type that represents an ICU mutex. michael@0: * For user-implemented mutexes, the value will typically point to a michael@0: * struct or object that implements the mutex. michael@0: * @deprecated ICU 52. This type is no longer supported. michael@0: * @system michael@0: */ michael@0: typedef void *UMTX; michael@0: michael@0: /** michael@0: * Function Pointer type for a user supplied mutex initialization function. michael@0: * The user-supplied function will be called by ICU whenever ICU needs to create a michael@0: * new mutex. The function implementation should create a mutex, and store a pointer michael@0: * to something that uniquely identifies the mutex into the UMTX that is supplied michael@0: * as a paramter. michael@0: * @param context user supplied value, obtained from from u_setMutexFunctions(). michael@0: * @param mutex Receives a pointer that identifies the new mutex. michael@0: * The mutex init function must set the UMTX to a non-null value. michael@0: * Subsequent calls by ICU to lock, unlock, or destroy a mutex will michael@0: * identify the mutex by the UMTX value. michael@0: * @param status Error status. Report errors back to ICU by setting this variable michael@0: * with an error code. michael@0: * @deprecated ICU 52. This function is no longer supported. michael@0: * @system michael@0: */ michael@0: typedef void U_CALLCONV UMtxInitFn (const void *context, UMTX *mutex, UErrorCode* status); michael@0: michael@0: michael@0: /** michael@0: * Function Pointer type for a user supplied mutex functions. michael@0: * One of the user-supplied functions with this signature will be called by ICU michael@0: * whenever ICU needs to lock, unlock, or destroy a mutex. michael@0: * @param context user supplied value, obtained from from u_setMutexFunctions(). michael@0: * @param mutex specify the mutex on which to operate. michael@0: * @deprecated ICU 52. This function is no longer supported. michael@0: * @system michael@0: */ michael@0: typedef void U_CALLCONV UMtxFn (const void *context, UMTX *mutex); michael@0: michael@0: michael@0: /** michael@0: * Set the functions that ICU will use for mutex operations michael@0: * Use of this function is optional; by default (without this function), ICU will michael@0: * directly access system functions for mutex operations michael@0: * This function can only be used when ICU is in an initial, unused state, before michael@0: * u_init() has been called. michael@0: * @param context This pointer value will be saved, and then (later) passed as michael@0: * a parameter to the user-supplied mutex functions each time they michael@0: * are called. michael@0: * @param init Pointer to a mutex initialization function. Must be non-null. michael@0: * @param destroy Pointer to the mutex destroy function. Must be non-null. michael@0: * @param lock pointer to the mutex lock function. Must be non-null. michael@0: * @param unlock Pointer to the mutex unlock function. Must be non-null. michael@0: * @param status Receives error values. michael@0: * @deprecated ICU 52. This function is no longer supported. michael@0: * @system michael@0: */ michael@0: U_DEPRECATED void U_EXPORT2 michael@0: u_setMutexFunctions(const void *context, UMtxInitFn *init, UMtxFn *destroy, UMtxFn *lock, UMtxFn *unlock, michael@0: UErrorCode *status); michael@0: michael@0: michael@0: /** michael@0: * Pointer type for a user supplied atomic increment or decrement function. michael@0: * @param context user supplied value, obtained from from u_setAtomicIncDecFunctions(). michael@0: * @param p Pointer to a 32 bit int to be incremented or decremented michael@0: * @return The value of the variable after the inc or dec operation. michael@0: * @deprecated ICU 52. This function is no longer supported. michael@0: * @system michael@0: */ michael@0: typedef int32_t U_CALLCONV UMtxAtomicFn(const void *context, int32_t *p); michael@0: michael@0: /** michael@0: * Set the functions that ICU will use for atomic increment and decrement of int32_t values. michael@0: * Use of this function is optional; by default (without this function), ICU will michael@0: * use its own internal implementation of atomic increment/decrement. michael@0: * This function can only be used when ICU is in an initial, unused state, before michael@0: * u_init() has been called. michael@0: * @param context This pointer value will be saved, and then (later) passed as michael@0: * a parameter to the increment and decrement functions each time they michael@0: * are called. This function can only be called michael@0: * @param inc Pointer to a function to do an atomic increment operation. Must be non-null. michael@0: * @param dec Pointer to a function to do an atomic decrement operation. Must be non-null. michael@0: * @param status Receives error values. michael@0: * @deprecated ICU 52. This function is no longer supported. michael@0: * @system michael@0: */ michael@0: U_DEPRECATED void U_EXPORT2 michael@0: u_setAtomicIncDecFunctions(const void *context, UMtxAtomicFn *inc, UMtxAtomicFn *dec, michael@0: UErrorCode *status); michael@0: michael@0: #endif /* U_HIDE_SYSTEM_API */ michael@0: michael@0: #endif