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