]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
73c04bcf A |
3 | /* |
4 | ****************************************************************************** | |
5 | * * | |
57a6839d | 6 | * Copyright (C) 2001-2014, International Business Machines * |
73c04bcf A |
7 | * Corporation and others. All Rights Reserved. * |
8 | * * | |
9 | ****************************************************************************** | |
b331163b | 10 | * file name: ucln_io.cpp |
f3c0d7a5 | 11 | * encoding: UTF-8 |
73c04bcf A |
12 | * tab size: 8 (not used) |
13 | * indentation:4 | |
14 | * | |
15 | * created on: 2006August11 | |
16 | * created by: George Rhoten | |
17 | */ | |
18 | ||
b331163b | 19 | #include "mutex.h" |
73c04bcf A |
20 | #include "ucln.h" |
21 | #include "ucln_io.h" | |
73c04bcf A |
22 | #include "uassert.h" |
23 | ||
4388f060 A |
24 | #ifndef U_IO_IMPLEMENTATION |
25 | #error U_IO_IMPLEMENTATION not set - must be set for all ICU source files in io/ - see http://userguide.icu-project.org/howtouseicu | |
26 | #endif | |
27 | ||
28 | ||
729e4ab9 A |
29 | /** Auto-client */ |
30 | #define UCLN_TYPE UCLN_IO | |
31 | #include "ucln_imp.h" | |
32 | ||
73c04bcf A |
33 | /* Leave this copyright notice here! It needs to go somewhere in this library. */ |
34 | static const char copyright[] = U_COPYRIGHT_STRING; | |
35 | ||
36 | static cleanupFunc *gCleanupFunctions[UCLN_IO_COUNT]; | |
37 | ||
f3c0d7a5 | 38 | static UBool U_CALLCONV io_cleanup(void) |
73c04bcf | 39 | { |
b331163b | 40 | int32_t libType = UCLN_IO_START; |
73c04bcf | 41 | |
57a6839d | 42 | (void)copyright; // Suppress unused variable warning. |
73c04bcf A |
43 | while (++libType<UCLN_IO_COUNT) { |
44 | if (gCleanupFunctions[libType]) | |
45 | { | |
46 | gCleanupFunctions[libType](); | |
47 | gCleanupFunctions[libType] = NULL; | |
48 | } | |
49 | } | |
729e4ab9 A |
50 | #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL)) |
51 | ucln_unRegisterAutomaticCleanup(); | |
52 | #endif | |
73c04bcf A |
53 | return TRUE; |
54 | } | |
55 | ||
56 | void ucln_io_registerCleanup(ECleanupIOType type, | |
b331163b | 57 | cleanupFunc *func) { |
73c04bcf | 58 | U_ASSERT(UCLN_IO_START < type && type < UCLN_IO_COUNT); |
73c04bcf | 59 | { |
b331163b A |
60 | icu::Mutex m; // See ticket 10295 for discussion. |
61 | ucln_registerCleanup(UCLN_IO, io_cleanup); | |
62 | if (UCLN_IO_START < type && type < UCLN_IO_COUNT) { | |
63 | gCleanupFunctions[type] = func; | |
64 | } | |
73c04bcf | 65 | } |
729e4ab9 A |
66 | |
67 | #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL)) | |
68 | ucln_registerAutomaticCleanup(); | |
69 | #endif | |
73c04bcf A |
70 | } |
71 |