From: Andy Heninger Date: Wed, 9 Feb 2022 00:31:34 +0000 (-0800) Subject: ICU-21832 Remove unsafe double-checked lock in ICUNotifier X-Git-Tag: cldr/2022-02-22~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=91732e7c55ba8177b34c989ab3c9936864e6f954;p=icu 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. --- 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); } } }