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