]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/servnotf.cpp
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / common / servnotf.cpp
index dbcbe92df802df645adbe8fc9f01af9c6ffc0047..e7a7ca50f0b8c67cf2930b5a9bdeb0887c1c652b 100644 (file)
@@ -1,3 +1,5 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /**
  *******************************************************************************
  * Copyright (C) 2001-2012, International Business Machines Corporation and    *
@@ -19,7 +21,10 @@ U_NAMESPACE_BEGIN
 EventListener::~EventListener() {}
 UOBJECT_DEFINE_RTTI_IMPLEMENTATION(EventListener)
 
-static UMutex notifyLock = U_MUTEX_INITIALIZER;
+static UMutex *notifyLock() {
+    static UMutex *m = STATIC_NEW(UMutex);
+    return m;
+}
 
 ICUNotifier::ICUNotifier(void) 
 : listeners(NULL) 
@@ -28,7 +33,7 @@ ICUNotifier::ICUNotifier(void)
 
 ICUNotifier::~ICUNotifier(void) {
     {
-        Mutex lmx(&notifyLock);
+        Mutex lmx(notifyLock());
         delete listeners;
         listeners = NULL;
     }
@@ -45,7 +50,7 @@ ICUNotifier::addListener(const EventListener* l, UErrorCode& status)
         }
 
         if (acceptsListener(*l)) {
-            Mutex lmx(&notifyLock);
+            Mutex lmx(notifyLock());
             if (listeners == NULL) {
                 listeners = new UVector(5, status);
             } else {
@@ -78,7 +83,7 @@ ICUNotifier::removeListener(const EventListener *l, UErrorCode& status)
         }
 
         {
-            Mutex lmx(&notifyLock);
+            Mutex lmx(notifyLock());
             if (listeners != NULL) {
                 // identity equality check
                 for (int i = 0, e = listeners->size(); i < e; ++i) {
@@ -101,7 +106,7 @@ void
 ICUNotifier::notifyChanged(void) 
 {
     if (listeners != NULL) {
-        Mutex lmx(&notifyLock);
+        Mutex lmx(notifyLock());
         if (listeners != NULL) {
             for (int i = 0, e = listeners->size(); i < e; ++i) {
                 EventListener* el = (EventListener*)listeners->elementAt(i);