]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/ucln.h
ICU-57131.0.1.tar.gz
[apple/icu.git] / icuSources / common / ucln.h
CommitLineData
b75a7d8f
A
1/*
2******************************************************************************
4388f060 3*
57a6839d 4* Copyright (C) 2001-2013, International Business Machines
4388f060
A
5* Corporation and others. All Rights Reserved.
6*
b75a7d8f 7******************************************************************************
4388f060 8* file name: ucln.h
b75a7d8f
A
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
22/** These are the functions used to register a library's memory cleanup
23 * functions. Each library should define a single library register function
24 * to call this API. In the i18n library, it is ucln_i18n_registerCleanup().
25 *
26 * None of the cleanup functions should use a mutex to clean up an API's
27 * allocated memory because a cleanup function is not meant to be thread safe,
28 * and plenty of data cannot be reference counted in order to make sure that
29 * no one else needs the allocated data.
30 *
31 * In order to make a cleanup function get called when u_cleanup is called,
32 * You should add your function to the library specific cleanup function.
33 * If the cleanup function is not in the common library, the code that
34 * allocates the memory should call the library specific cleanup function.
35 * For instance, in the i18n library, any memory allocated statically must
36 * call ucln_i18n_registerCleanup() from the ucln_in.h header. These library
37 * cleanup functions are needed in order to prevent a circular dependency
38 * between the common library and any other library.
39 *
40 * The order of the cleanup is very important. In general, an API that
41 * depends on a second API should be cleaned up before the second API.
42 * For instance, the default converter in ustring depends upon the converter
43 * API. So the default converter should be closed before the converter API
44 * has its cache flushed. This will prevent any memory leaks due to
45 * reference counting.
46 *
47 * Please see common/ucln_cmn.{h,c} and i18n/ucln_in.{h,c} for examples.
48 */
49
729e4ab9
A
50/**
51 * Data Type for cleanup function selector. These roughly correspond to libraries.
52 */
b75a7d8f
A
53typedef enum ECleanupLibraryType {
54 UCLN_START = -1,
729e4ab9 55 UCLN_UPLUG, /* ICU plugins */
b75a7d8f 56 UCLN_CUSTOM, /* Custom is for anyone else. */
46f4442e 57 UCLN_CTESTFW,
729e4ab9 58 UCLN_TOOLUTIL,
b75a7d8f 59 UCLN_LAYOUTEX,
374ca955
A
60 UCLN_LAYOUT,
61 UCLN_IO,
b75a7d8f
A
62 UCLN_I18N,
63 UCLN_COMMON /* This must be the last one to cleanup. */
64} ECleanupLibraryType;
65
729e4ab9
A
66/**
67 * Data type for cleanup function pointer
68 */
374ca955
A
69U_CDECL_BEGIN
70typedef UBool U_CALLCONV cleanupFunc(void);
51004dcb 71typedef void U_CALLCONV initFunc(UErrorCode *);
374ca955 72U_CDECL_END
b75a7d8f 73
729e4ab9
A
74/**
75 * Register a cleanup function
76 * @param type which library to register for.
77 * @param func the function pointer
78 */
b75a7d8f
A
79U_CAPI void U_EXPORT2 ucln_registerCleanup(ECleanupLibraryType type,
80 cleanupFunc *func);
81
729e4ab9
A
82/**
83 * Request cleanup for one specific library.
84 * Not thread safe.
729e4ab9
A
85 * @param type which library to cleanup
86 */
87U_CAPI void U_EXPORT2 ucln_cleanupOne(ECleanupLibraryType type);
88
b75a7d8f 89#endif