]> granicus.if.org Git - icu/commitdiff
ICU-12027 Improved thread safety of RuleBasedTransliterator.
authorAndy Heninger <andy.heninger@gmail.com>
Tue, 8 Dec 2015 01:29:24 +0000 (01:29 +0000)
committerAndy Heninger <andy.heninger@gmail.com>
Tue, 8 Dec 2015 01:29:24 +0000 (01:29 +0000)
X-SVN-Rev: 38110

icu4c/source/i18n/rbt.cpp

index 5c4d3beaee5ece34a2951ef7d06b04009da29deb..cf8f31f00c7f3acf045f021e05ce177642c4fe74 100644 (file)
@@ -240,31 +240,27 @@ RuleBasedTransliterator::handleTransliterate(Replaceable& text, UTransPosition&
     //   Double-locking must be prevented in these cases.
     //   
 
-    // If the transliteration data is exclusively owned by this transliterator object,
-    //   we don't need to do any locking.  No sharing between transliterators is possible,
-    //   so no concurrent access from multiple threads is possible.
     UBool    lockedMutexAtThisLevel = FALSE;
-    if (isDataOwned == FALSE) {
-        // Test whether this request is operating on the same text string as
-        //   some other transliteration that is still in progress and holding the 
-        //   transliteration mutex.  If so, do not lock the transliteration
-        //    mutex again.
-        //
-        //  gLockedText variable is protected by the global ICU mutex.
-        //  Shared RBT data protected by transliteratorDataMutex.
-        //
-        // TODO(andy): Need a better scheme for handling this.
-        UBool needToLock;
-        {
-            Mutex m;
-            needToLock = (&text != gLockedText);
-        }
-        if (needToLock) {
-            umtx_lock(&transliteratorDataMutex);  // Contention, longish waits possible here.
-            Mutex m;
-            gLockedText = &text;
-            lockedMutexAtThisLevel = TRUE;
-        }
+
+    // Test whether this request is operating on the same text string as
+    //   some other transliteration that is still in progress and holding the 
+    //   transliteration mutex.  If so, do not lock the transliteration
+    //    mutex again.
+    //
+    //  gLockedText variable is protected by the global ICU mutex.
+    //  Shared RBT data protected by transliteratorDataMutex.
+    //
+    // TODO(andy): Need a better scheme for handling this.
+    UBool needToLock;
+    {
+        Mutex m;
+        needToLock = (&text != gLockedText);
+    }
+    if (needToLock) {
+        umtx_lock(&transliteratorDataMutex);  // Contention, longish waits possible here.
+        Mutex m;
+        gLockedText = &text;
+        lockedMutexAtThisLevel = TRUE;
     }
     
     // Check to make sure we don't dereference a null pointer.