From 91732e7c55ba8177b34c989ab3c9936864e6f954 Mon Sep 17 00:00:00 2001 From: Andy Heninger Date: Tue, 8 Feb 2022 16:31:34 -0800 Subject: [PATCH] ICU-21832 Remove unsafe double-checked lock in ICUNotifier ICUNotifier::notifyChanged() was using the thread-unsafe double-checked lock idiom. Replace it with use of the mutex only. --- icu4c/source/common/servnotf.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/icu4c/source/common/servnotf.cpp b/icu4c/source/common/servnotf.cpp index 10183d3a2dc..d9fb3887520 100644 --- a/icu4c/source/common/servnotf.cpp +++ b/icu4c/source/common/servnotf.cpp @@ -106,13 +106,11 @@ ICUNotifier::removeListener(const EventListener *l, UErrorCode& status) void ICUNotifier::notifyChanged(void) { + Mutex lmx(¬ifyLock); if (listeners != NULL) { - Mutex lmx(¬ifyLock); - if (listeners != NULL) { - for (int i = 0, e = listeners->size(); i < e; ++i) { - EventListener* el = (EventListener*)listeners->elementAt(i); - notifyListener(*el); - } + for (int i = 0, e = listeners->size(); i < e; ++i) { + EventListener* el = (EventListener*)listeners->elementAt(i); + notifyListener(*el); } } }