1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others. 2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html 3*0e209d39SAndroid Build Coastguard Worker /* 4*0e209d39SAndroid Build Coastguard Worker ****************************************************************************** 5*0e209d39SAndroid Build Coastguard Worker * 6*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 2001-2013, International Business Machines 7*0e209d39SAndroid Build Coastguard Worker * Corporation and others. All Rights Reserved. 8*0e209d39SAndroid Build Coastguard Worker * 9*0e209d39SAndroid Build Coastguard Worker ****************************************************************************** 10*0e209d39SAndroid Build Coastguard Worker * file name: ucln.h 11*0e209d39SAndroid Build Coastguard Worker * encoding: UTF-8 12*0e209d39SAndroid Build Coastguard Worker * tab size: 8 (not used) 13*0e209d39SAndroid Build Coastguard Worker * indentation:4 14*0e209d39SAndroid Build Coastguard Worker * 15*0e209d39SAndroid Build Coastguard Worker * created on: 2001July05 16*0e209d39SAndroid Build Coastguard Worker * created by: George Rhoten 17*0e209d39SAndroid Build Coastguard Worker */ 18*0e209d39SAndroid Build Coastguard Worker 19*0e209d39SAndroid Build Coastguard Worker #ifndef __UCLN_H__ 20*0e209d39SAndroid Build Coastguard Worker #define __UCLN_H__ 21*0e209d39SAndroid Build Coastguard Worker 22*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h" 23*0e209d39SAndroid Build Coastguard Worker 24*0e209d39SAndroid Build Coastguard Worker /** These are the functions used to register a library's memory cleanup 25*0e209d39SAndroid Build Coastguard Worker * functions. Each library should define a single library register function 26*0e209d39SAndroid Build Coastguard Worker * to call this API. In the i18n library, it is ucln_i18n_registerCleanup(). 27*0e209d39SAndroid Build Coastguard Worker * 28*0e209d39SAndroid Build Coastguard Worker * None of the cleanup functions should use a mutex to clean up an API's 29*0e209d39SAndroid Build Coastguard Worker * allocated memory because a cleanup function is not meant to be thread safe, 30*0e209d39SAndroid Build Coastguard Worker * and plenty of data cannot be reference counted in order to make sure that 31*0e209d39SAndroid Build Coastguard Worker * no one else needs the allocated data. 32*0e209d39SAndroid Build Coastguard Worker * 33*0e209d39SAndroid Build Coastguard Worker * In order to make a cleanup function get called when u_cleanup is called, 34*0e209d39SAndroid Build Coastguard Worker * You should add your function to the library specific cleanup function. 35*0e209d39SAndroid Build Coastguard Worker * If the cleanup function is not in the common library, the code that 36*0e209d39SAndroid Build Coastguard Worker * allocates the memory should call the library specific cleanup function. 37*0e209d39SAndroid Build Coastguard Worker * For instance, in the i18n library, any memory allocated statically must 38*0e209d39SAndroid Build Coastguard Worker * call ucln_i18n_registerCleanup() from the ucln_in.h header. These library 39*0e209d39SAndroid Build Coastguard Worker * cleanup functions are needed in order to prevent a circular dependency 40*0e209d39SAndroid Build Coastguard Worker * between the common library and any other library. 41*0e209d39SAndroid Build Coastguard Worker * 42*0e209d39SAndroid Build Coastguard Worker * The order of the cleanup is very important. In general, an API that 43*0e209d39SAndroid Build Coastguard Worker * depends on a second API should be cleaned up before the second API. 44*0e209d39SAndroid Build Coastguard Worker * For instance, the default converter in ustring depends upon the converter 45*0e209d39SAndroid Build Coastguard Worker * API. So the default converter should be closed before the converter API 46*0e209d39SAndroid Build Coastguard Worker * has its cache flushed. This will prevent any memory leaks due to 47*0e209d39SAndroid Build Coastguard Worker * reference counting. 48*0e209d39SAndroid Build Coastguard Worker * 49*0e209d39SAndroid Build Coastguard Worker * Please see common/ucln_cmn.{h,c} and i18n/ucln_in.{h,c} for examples. 50*0e209d39SAndroid Build Coastguard Worker */ 51*0e209d39SAndroid Build Coastguard Worker 52*0e209d39SAndroid Build Coastguard Worker /** 53*0e209d39SAndroid Build Coastguard Worker * Data Type for cleanup function selector. These roughly correspond to libraries. 54*0e209d39SAndroid Build Coastguard Worker */ 55*0e209d39SAndroid Build Coastguard Worker typedef enum ECleanupLibraryType { 56*0e209d39SAndroid Build Coastguard Worker UCLN_START = -1, 57*0e209d39SAndroid Build Coastguard Worker UCLN_UPLUG, /* ICU plugins */ 58*0e209d39SAndroid Build Coastguard Worker UCLN_CUSTOM, /* Custom is for anyone else. */ 59*0e209d39SAndroid Build Coastguard Worker UCLN_CTESTFW, 60*0e209d39SAndroid Build Coastguard Worker UCLN_TOOLUTIL, 61*0e209d39SAndroid Build Coastguard Worker UCLN_LAYOUTEX, 62*0e209d39SAndroid Build Coastguard Worker UCLN_LAYOUT, 63*0e209d39SAndroid Build Coastguard Worker UCLN_IO, 64*0e209d39SAndroid Build Coastguard Worker UCLN_I18N, 65*0e209d39SAndroid Build Coastguard Worker UCLN_COMMON /* This must be the last one to cleanup. */ 66*0e209d39SAndroid Build Coastguard Worker } ECleanupLibraryType; 67*0e209d39SAndroid Build Coastguard Worker 68*0e209d39SAndroid Build Coastguard Worker /** 69*0e209d39SAndroid Build Coastguard Worker * Data type for cleanup function pointer 70*0e209d39SAndroid Build Coastguard Worker */ 71*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN 72*0e209d39SAndroid Build Coastguard Worker typedef UBool U_CALLCONV cleanupFunc(void); 73*0e209d39SAndroid Build Coastguard Worker typedef void U_CALLCONV initFunc(UErrorCode *); 74*0e209d39SAndroid Build Coastguard Worker U_CDECL_END 75*0e209d39SAndroid Build Coastguard Worker 76*0e209d39SAndroid Build Coastguard Worker /** 77*0e209d39SAndroid Build Coastguard Worker * Register a cleanup function 78*0e209d39SAndroid Build Coastguard Worker * @param type which library to register for. 79*0e209d39SAndroid Build Coastguard Worker * @param func the function pointer 80*0e209d39SAndroid Build Coastguard Worker */ 81*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 ucln_registerCleanup(ECleanupLibraryType type, 82*0e209d39SAndroid Build Coastguard Worker cleanupFunc *func); 83*0e209d39SAndroid Build Coastguard Worker 84*0e209d39SAndroid Build Coastguard Worker /** 85*0e209d39SAndroid Build Coastguard Worker * Request cleanup for one specific library. 86*0e209d39SAndroid Build Coastguard Worker * Not thread safe. 87*0e209d39SAndroid Build Coastguard Worker * @param type which library to cleanup 88*0e209d39SAndroid Build Coastguard Worker */ 89*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2 ucln_cleanupOne(ECleanupLibraryType type); 90*0e209d39SAndroid Build Coastguard Worker 91*0e209d39SAndroid Build Coastguard Worker #endif 92