diff --git a/icu4c/source/common/ucln_cmn.cpp b/icu4c/source/common/ucln_cmn.cpp index 42e7019a503..2480c9d3fd2 100644 --- a/icu4c/source/common/ucln_cmn.cpp +++ b/icu4c/source/common/ucln_cmn.cpp @@ -14,12 +14,13 @@ #include "unicode/utypes.h" #include "unicode/uclean.h" -#include "utracimp.h" -#include "ucln_cmn.h" -#include "cmutex.h" -#include "ucln.h" #include "cmemory.h" +#include "mutex.h" #include "uassert.h" +#include "ucln.h" +#include "ucln_cmn.h" +#include "utracimp.h" +#include "umutex.h" /** Auto-client for UCLN_COMMON **/ #define UCLN_TYPE_IS_COMMON @@ -65,6 +66,7 @@ ucln_common_registerCleanup(ECleanupCommonType type, U_ASSERT(UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT); if (UCLN_COMMON_START < type && type < UCLN_COMMON_COUNT) { + icu::Mutex m; // See ticket 10295 for discussion. gCommonCleanupFunctions[type] = func; } #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL)) @@ -72,6 +74,10 @@ ucln_common_registerCleanup(ECleanupCommonType type, #endif } +// Note: ucln_registerCleanup() is called with the ICU global mutex locked. +// Be aware if adding anything to the function. +// See ticket 10295 for discussion. + U_CAPI void U_EXPORT2 ucln_registerCleanup(ECleanupLibraryType type, cleanupFunc *func) diff --git a/icu4c/source/i18n/ucln_in.cpp b/icu4c/source/i18n/ucln_in.cpp index ee2a6f1dbba..431d43161e7 100644 --- a/icu4c/source/i18n/ucln_in.cpp +++ b/icu4c/source/i18n/ucln_in.cpp @@ -16,6 +16,7 @@ #include "ucln.h" #include "ucln_in.h" +#include "mutex.h" #include "uassert.h" /** Auto-client for UCLN_I18N **/ @@ -46,13 +47,14 @@ static UBool i18n_cleanup(void) } void ucln_i18n_registerCleanup(ECleanupI18NType type, - cleanupFunc *func) -{ + cleanupFunc *func) { U_ASSERT(UCLN_I18N_START < type && type < UCLN_I18N_COUNT); - ucln_registerCleanup(UCLN_I18N, i18n_cleanup); - if (UCLN_I18N_START < type && type < UCLN_I18N_COUNT) { - gCleanupFunctions[type] = func; + icu::Mutex m; // See ticket 10295 for discussion. + ucln_registerCleanup(UCLN_I18N, i18n_cleanup); + if (UCLN_I18N_START < type && type < UCLN_I18N_COUNT) { + gCleanupFunctions[type] = func; + } } #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL)) ucln_registerAutomaticCleanup(); diff --git a/icu4c/source/io/ucln_io.cpp b/icu4c/source/io/ucln_io.cpp index ab7b5d9c122..1775d5c5094 100644 --- a/icu4c/source/io/ucln_io.cpp +++ b/icu4c/source/io/ucln_io.cpp @@ -14,6 +14,7 @@ * created by: George Rhoten */ +#include "mutex.h" #include "ucln.h" #include "ucln_io.h" #include "uassert.h" @@ -51,13 +52,14 @@ static UBool io_cleanup(void) } void ucln_io_registerCleanup(ECleanupIOType type, - cleanupFunc *func) -{ + cleanupFunc *func) { U_ASSERT(UCLN_IO_START < type && type < UCLN_IO_COUNT); - ucln_registerCleanup(UCLN_IO, io_cleanup); - if (UCLN_IO_START < type && type < UCLN_IO_COUNT) { - gCleanupFunctions[type] = func; + icu::Mutex m; // See ticket 10295 for discussion. + ucln_registerCleanup(UCLN_IO, io_cleanup); + if (UCLN_IO_START < type && type < UCLN_IO_COUNT) { + gCleanupFunctions[type] = func; + } } #if !UCLN_NO_AUTO_CLEANUP && (defined(UCLN_AUTO_ATEXIT) || defined(UCLN_AUTO_LOCAL))