2011-06-27 Joseph Pecoraro <joepeck@webkit.org>
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Jun 2011 23:57:48 +0000 (23:57 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Jun 2011 23:57:48 +0000 (23:57 +0000)
        Reviewed by Darin Adler.

        Allow non-main thread text drawing in ICU ports
        https://bugs.webkit.org/show_bug.cgi?id=63482

        Some ports allow multiple threads to draw strings.
        LineBreakIteratorPool is not thread safe and the existing
        ASSERT caught cases where multiple threads were trying
        to access the shared pool. This makes the pool a lazily
        created per-thread pool to allow for thread safe pool use.

        * platform/ThreadGlobalData.h:
        * platform/ThreadGlobalData.cpp:
        (WebCore::ThreadGlobalData::ThreadGlobalData): start with null.
        (WebCore::ThreadGlobalData::lineBreakIteratorPool): lazily create.
        (WebCore::ThreadGlobalData::destroy): delete.
        Manage the lifetime of the per-thread pool instance.

        * platform/text/LineBreakIteratorPoolICU.h:
        (WebCore::LineBreakIteratorPool::sharedPool):
        Use the per-thread pool instance and remove the ASSERT that
        this needs to be on the main thread.

        (WebCore::LineBreakIteratorPool::create):
        Create a PassOwnPtr so we can use OwnPtr on pools.

        (WebCore::LineBreakIteratorPool::LineBreakIteratorPool):
        Private now that there is a public create function.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@89878 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/ThreadGlobalData.cpp
Source/WebCore/platform/ThreadGlobalData.h
Source/WebCore/platform/text/LineBreakIteratorPoolICU.h

index b4308c04c2f69f976decd53171fdb5fb397c6765..16f1fd2aebb6dde4ff537d759ea0133cde19edd4 100644 (file)
         * platform/mac/WebVideoFullscreenController.h:
         * platform/mac/WebVideoFullscreenHUDWindowController.h:
 
+2011-06-27  Joseph Pecoraro  <joepeck@webkit.org>
+
+        Reviewed by Darin Adler.
+
+        Allow non-main thread text drawing in ICU ports
+        https://bugs.webkit.org/show_bug.cgi?id=63482
+
+        Some ports allow multiple threads to draw strings.
+        LineBreakIteratorPool is not thread safe and the existing
+        ASSERT caught cases where multiple threads were trying
+        to access the shared pool. This makes the pool a lazily
+        created per-thread pool to allow for thread safe pool use.
+
+        * platform/ThreadGlobalData.h:
+        * platform/ThreadGlobalData.cpp:
+        (WebCore::ThreadGlobalData::ThreadGlobalData): start with null.
+        (WebCore::ThreadGlobalData::lineBreakIteratorPool): lazily create.
+        (WebCore::ThreadGlobalData::destroy): delete.
+        Manage the lifetime of the per-thread pool instance.
+
+        * platform/text/LineBreakIteratorPoolICU.h:
+        (WebCore::LineBreakIteratorPool::sharedPool):
+        Use the per-thread pool instance and remove the ASSERT that
+        this needs to be on the main thread.
+
+        (WebCore::LineBreakIteratorPool::create):
+        Create a PassOwnPtr so we can use OwnPtr on pools.
+
+        (WebCore::LineBreakIteratorPool::LineBreakIteratorPool):
+        Private now that there is a public create function.
+
 2011-06-27  Joseph Pecoraro  <joepeck@webkit.org>
 
         Reviewed by Darin Adler.
index 6d7eb51d6f05208b50ba05acfc369f1954a1667e..90933b9c3b0f0598aa594c60a95b1b185d118c72 100644 (file)
@@ -34,6 +34,7 @@
 #include <wtf/text/StringImpl.h>
 
 #if USE(ICU_UNICODE)
+#include "LineBreakIteratorPoolICU.h"
 #include "TextCodecICU.h"
 #endif
 
@@ -81,6 +82,15 @@ ThreadGlobalData::~ThreadGlobalData()
     destroy();
 }
 
+#if USE(ICU_UNICODE)
+LineBreakIteratorPool& ThreadGlobalData::lineBreakIteratorPool()
+{
+    if (!m_lineBreakIteratorPool)
+        m_lineBreakIteratorPool = LineBreakIteratorPool::create();
+    return *m_lineBreakIteratorPool;
+}
+#endif
+
 void ThreadGlobalData::destroy()
 {
 #if PLATFORM(MAC)
@@ -91,6 +101,7 @@ void ThreadGlobalData::destroy()
 #if USE(ICU_UNICODE)
     delete m_cachedConverterICU;
     m_cachedConverterICU = 0;
+    m_lineBreakIteratorPool = nullptr;
 #endif
 
     delete m_eventNames;
index 76377b49e090b9ae70775419848f2145cfe0f766..d1556367a8f3c6d0a0a52b706deb3a22dcc8877a 100644 (file)
@@ -30,6 +30,7 @@
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
 #include <wtf/Noncopyable.h>
+#include <wtf/OwnPtr.h>
 #include <wtf/text/StringHash.h>
 
 #if ENABLE(WORKERS)
@@ -41,9 +42,11 @@ using WTF::ThreadSpecific;
 namespace WebCore {
 
     class EventNames;
+    class LineBreakIteratorPool;
+    class ThreadTimers;
+
     struct ICUConverterWrapper;
     struct TECConverterWrapper;
-    class ThreadTimers;
 
     class ThreadGlobalData {
         WTF_MAKE_NONCOPYABLE(ThreadGlobalData);
@@ -57,6 +60,7 @@ namespace WebCore {
 
 #if USE(ICU_UNICODE)
         ICUConverterWrapper& cachedConverterICU() { return *m_cachedConverterICU; }
+        LineBreakIteratorPool& lineBreakIteratorPool();
 #endif
 
 #if PLATFORM(MAC)
@@ -73,6 +77,7 @@ namespace WebCore {
 
 #if USE(ICU_UNICODE)
         ICUConverterWrapper* m_cachedConverterICU;
+        OwnPtr<LineBreakIteratorPool> m_lineBreakIteratorPool;
 #endif
 
 #if PLATFORM(MAC)
index f8061a09aae5e40594851fe2aeec86e455b4d694..11b1150312d9638c1ee7da0491ba6e9df59edd77 100644 (file)
 #define LineBreakIteratorPoolICU_h
 
 #include "TextBreakIteratorInternalICU.h"
+#include "ThreadGlobalData.h"
 #include <unicode/ubrk.h>
 #include <wtf/Assertions.h>
 #include <wtf/HashMap.h>
+#include <wtf/PassOwnPtr.h>
 #include <wtf/text/CString.h>
 
 namespace WebCore {
@@ -39,12 +41,10 @@ class LineBreakIteratorPool {
 public:
     static LineBreakIteratorPool& sharedPool()
     {
-        ASSERT(isMainThread());
-        DEFINE_STATIC_LOCAL(LineBreakIteratorPool, pool, ());
-        return pool;
+        return threadGlobalData().lineBreakIteratorPool();
     }
 
-    LineBreakIteratorPool() { }
+    static PassOwnPtr<LineBreakIteratorPool> create() { return adoptPtr(new LineBreakIteratorPool); }
 
     UBreakIterator* take(const AtomicString& locale)
     {
@@ -84,6 +84,8 @@ public:
     }
 
 private:
+    LineBreakIteratorPool() { }
+
     static const size_t capacity = 4;
 
     typedef pair<AtomicString, UBreakIterator*> Entry;