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