Title: [118587] trunk/Source/WebCore
Revision
118587
Author
[email protected]
Date
2012-05-25 16:46:28 -0700 (Fri, 25 May 2012)

Log Message

Make the ICU-based implementation of NonSharedCharacterBreakIterator work in configurations
that do not have COMPARE_AND_SWAP enabled.

Reviewed by Jessie Berlin.

* platform/text/TextBreakIteratorICU.cpp:
(WebCore::compareAndSwapNonSharedCharacterBreakIterator): Added this helper. It uses
weakCompareAndSwap when COMPARE_AND_SWAP is enabled, and uses a mutex to do the atomic
compare and swap otherwise.
(WebCore::NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator): Changed to use
compareAndSwapNonSharedCharacterBreakIterator().
(WebCore::NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (118586 => 118587)


--- trunk/Source/WebCore/ChangeLog	2012-05-25 23:31:39 UTC (rev 118586)
+++ trunk/Source/WebCore/ChangeLog	2012-05-25 23:46:28 UTC (rev 118587)
@@ -1,3 +1,18 @@
+2012-05-25  Dan Bernstein  <[email protected]>
+
+        Make the ICU-based implementation of NonSharedCharacterBreakIterator work in configurations
+        that do not have COMPARE_AND_SWAP enabled.
+
+        Reviewed by Jessie Berlin.
+
+        * platform/text/TextBreakIteratorICU.cpp:
+        (WebCore::compareAndSwapNonSharedCharacterBreakIterator): Added this helper. It uses
+        weakCompareAndSwap when COMPARE_AND_SWAP is enabled, and uses a mutex to do the atomic
+        compare and swap otherwise.
+        (WebCore::NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator): Changed to use
+        compareAndSwapNonSharedCharacterBreakIterator().
+        (WebCore::NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator): Ditto.
+
 2012-05-25  Tommy Widenflycht  <[email protected]>
 
         MediaStream API: Make sure IceCallback is valid for PeerConnection00

Modified: trunk/Source/WebCore/platform/text/TextBreakIteratorICU.cpp (118586 => 118587)


--- trunk/Source/WebCore/platform/text/TextBreakIteratorICU.cpp	2012-05-25 23:31:39 UTC (rev 118586)
+++ trunk/Source/WebCore/platform/text/TextBreakIteratorICU.cpp	2012-05-25 23:46:28 UTC (rev 118587)
@@ -87,16 +87,30 @@
 
 static TextBreakIterator* nonSharedCharacterBreakIterator;
 
+static inline bool compareAndSwapNonSharedCharacterBreakIterator(TextBreakIterator* expected, TextBreakIterator* newValue)
+{
+#if ENABLE(COMPARE_AND_SWAP)
+    return weakCompareAndSwap(reinterpret_cast<void**>(&nonSharedCharacterBreakIterator), expected, newValue);
+#else
+    DEFINE_STATIC_LOCAL(Mutex, nonSharedCharacterBreakIteratorMutex, ());
+    MutexLocker locker(nonSharedCharacterBreakIteratorMutex);
+    if (nonSharedCharacterBreakIterator != expected)
+        return false;
+    nonSharedCharacterBreakIterator = newValue;
+    return true;
+#endif
+}
+
 NonSharedCharacterBreakIterator::NonSharedCharacterBreakIterator(const UChar* buffer, int length)
 {
     m_iterator = nonSharedCharacterBreakIterator;
-    bool createdIterator = m_iterator && weakCompareAndSwap(reinterpret_cast<void**>(&nonSharedCharacterBreakIterator), m_iterator, 0);
+    bool createdIterator = m_iterator && compareAndSwapNonSharedCharacterBreakIterator(m_iterator, 0);
     m_iterator = setUpIterator(createdIterator, m_iterator, UBRK_CHARACTER, buffer, length);
 }
 
 NonSharedCharacterBreakIterator::~NonSharedCharacterBreakIterator()
 {
-    if (!weakCompareAndSwap(reinterpret_cast<void**>(&nonSharedCharacterBreakIterator), 0, m_iterator))
+    if (!compareAndSwapNonSharedCharacterBreakIterator(0, m_iterator))
         ubrk_close(reinterpret_cast<UBreakIterator*>(m_iterator));
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to