ucln_io.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  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
  11. * encoding: UTF-8
  12. * tab size: 8 (not used)
  13. * indentation:4
  14. *
  15. * created on: 2006August11
  16. * created by: George Rhoten
  17. */
  18. #include "unicode/utypes.h"
  19. #include "mutex.h"
  20. #include "ucln.h"
  21. #include "ucln_io.h"
  22. #include "uassert.h"
  23. #ifndef U_IO_IMPLEMENTATION
  24. #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
  25. #endif
  26. /** Auto-client */
  27. #define UCLN_TYPE UCLN_IO
  28. #include "ucln_imp.h"
  29. /* Leave this copyright notice here! It needs to go somewhere in this library. */
  30. static const char copyright[] = U_COPYRIGHT_STRING;
  31. static cleanupFunc *gCleanupFunctions[UCLN_IO_COUNT];
  32. static UBool U_CALLCONV io_cleanup()
  33. {
  34. int32_t libType = UCLN_IO_START;
  35. (void)copyright; // Suppress unused variable warning.
  36. while (++libType<UCLN_IO_COUNT) {
  37. if (gCleanupFunctions[libType])
  38. {
  39. gCleanupFunctions[libType]();
  40. gCleanupFunctions[libType] = nullptr;
  41. }
  42. }
  43. #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
  44. ucln_unRegisterAutomaticCleanup();
  45. #endif
  46. return true;
  47. }
  48. void ucln_io_registerCleanup(ECleanupIOType type,
  49. cleanupFunc *func) {
  50. U_ASSERT(UCLN_IO_START < type && type < UCLN_IO_COUNT);
  51. {
  52. icu::Mutex m; // See ticket 10295 for discussion.
  53. ucln_registerCleanup(UCLN_IO, io_cleanup);
  54. if (UCLN_IO_START < type && type < UCLN_IO_COUNT) {
  55. gCleanupFunctions[type] = func;
  56. }
  57. }
  58. #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))
  59. ucln_registerAutomaticCleanup();
  60. #endif
  61. }