michael@0: /* 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: ****************************************************************************** michael@0: * file name: ucln.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 __UCLN_H__ michael@0: #define __UCLN_H__ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: /** These are the functions used to register a library's memory cleanup michael@0: * functions. Each library should define a single library register function michael@0: * to call this API. In the i18n library, it is ucln_i18n_registerCleanup(). michael@0: * michael@0: * None of the cleanup functions should use a mutex to clean up an API's michael@0: * allocated memory because a cleanup function is not meant to be thread safe, michael@0: * and plenty of data cannot be reference counted in order to make sure that michael@0: * no one else needs the allocated data. michael@0: * michael@0: * In order to make a cleanup function get called when u_cleanup is called, michael@0: * You should add your function to the library specific cleanup function. michael@0: * If the cleanup function is not in the common library, the code that michael@0: * allocates the memory should call the library specific cleanup function. michael@0: * For instance, in the i18n library, any memory allocated statically must michael@0: * call ucln_i18n_registerCleanup() from the ucln_in.h header. These library michael@0: * cleanup functions are needed in order to prevent a circular dependency michael@0: * between the common library and any other library. michael@0: * michael@0: * The order of the cleanup is very important. In general, an API that michael@0: * depends on a second API should be cleaned up before the second API. michael@0: * For instance, the default converter in ustring depends upon the converter michael@0: * API. So the default converter should be closed before the converter API michael@0: * has its cache flushed. This will prevent any memory leaks due to michael@0: * reference counting. michael@0: * michael@0: * Please see common/ucln_cmn.{h,c} and i18n/ucln_in.{h,c} for examples. michael@0: */ michael@0: michael@0: /** michael@0: * Data Type for cleanup function selector. These roughly correspond to libraries. michael@0: */ michael@0: typedef enum ECleanupLibraryType { michael@0: UCLN_START = -1, michael@0: UCLN_UPLUG, /* ICU plugins */ michael@0: UCLN_CUSTOM, /* Custom is for anyone else. */ michael@0: UCLN_CTESTFW, michael@0: UCLN_TOOLUTIL, michael@0: UCLN_LAYOUTEX, michael@0: UCLN_LAYOUT, michael@0: UCLN_IO, michael@0: UCLN_I18N, michael@0: UCLN_COMMON /* This must be the last one to cleanup. */ michael@0: } ECleanupLibraryType; michael@0: michael@0: /** michael@0: * Data type for cleanup function pointer michael@0: */ michael@0: U_CDECL_BEGIN michael@0: typedef UBool U_CALLCONV cleanupFunc(void); michael@0: typedef void U_CALLCONV initFunc(UErrorCode *); michael@0: U_CDECL_END michael@0: michael@0: /** michael@0: * Register a cleanup function michael@0: * @param type which library to register for. michael@0: * @param func the function pointer michael@0: */ michael@0: U_CAPI void U_EXPORT2 ucln_registerCleanup(ECleanupLibraryType type, michael@0: cleanupFunc *func); michael@0: michael@0: /** michael@0: * Request cleanup for one specific library. michael@0: * Not thread safe. michael@0: * @param type which library to cleanup michael@0: */ michael@0: U_CAPI void U_EXPORT2 ucln_cleanupOne(ECleanupLibraryType type); michael@0: michael@0: #endif