ucln.h 3.1 KB

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