Title: [94893] trunk/Source/WebCore
Revision
94893
Author
crog...@google.com
Date
2011-09-09 17:59:43 -0700 (Fri, 09 Sep 2011)

Log Message

HRTFDatabaseLoader should not call WTF::waitForThreadCompletion() more than once
https://bugs.webkit.org/show_bug.cgi?id=67866

Reviewed by David Levin.

No new tests since this is difficult to test.
This is designed to fix existing webaudio layout test failures.

* platform/audio/HRTFDatabaseLoader.cpp:
(WebCore::HRTFDatabaseLoader::HRTFDatabaseLoader):
(WebCore::HRTFDatabaseLoader::~HRTFDatabaseLoader):
(WebCore::HRTFDatabaseLoader::loadAsynchronously):
(WebCore::HRTFDatabaseLoader::waitForLoaderThreadCompletion):
* platform/audio/HRTFDatabaseLoader.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (94892 => 94893)


--- trunk/Source/WebCore/ChangeLog	2011-09-10 00:57:43 UTC (rev 94892)
+++ trunk/Source/WebCore/ChangeLog	2011-09-10 00:59:43 UTC (rev 94893)
@@ -1,3 +1,20 @@
+2011-09-09  Chris Rogers  <crog...@google.com>
+
+        HRTFDatabaseLoader should not call WTF::waitForThreadCompletion() more than once
+        https://bugs.webkit.org/show_bug.cgi?id=67866
+
+        Reviewed by David Levin.
+
+        No new tests since this is difficult to test.
+        This is designed to fix existing webaudio layout test failures.
+
+        * platform/audio/HRTFDatabaseLoader.cpp:
+        (WebCore::HRTFDatabaseLoader::HRTFDatabaseLoader):
+        (WebCore::HRTFDatabaseLoader::~HRTFDatabaseLoader):
+        (WebCore::HRTFDatabaseLoader::loadAsynchronously):
+        (WebCore::HRTFDatabaseLoader::waitForLoaderThreadCompletion):
+        * platform/audio/HRTFDatabaseLoader.h:
+
 2011-09-09  Jessie Berlin  <jber...@apple.com>
 
         Cookies are not available after turning off Private Browsing after the last window has been

Modified: trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp (94892 => 94893)


--- trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp	2011-09-10 00:57:43 UTC (rev 94892)
+++ trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.cpp	2011-09-10 00:59:43 UTC (rev 94893)
@@ -61,7 +61,6 @@
 
 HRTFDatabaseLoader::HRTFDatabaseLoader(double sampleRate)
     : m_databaseLoaderThread(0)
-    , m_startedLoadingDatabase(false)
     , m_databaseSampleRate(sampleRate)
 {
     ASSERT(isMainThread());
@@ -71,12 +70,7 @@
 {
     ASSERT(isMainThread());
 
-    if (m_startedLoadingDatabase)
-        waitForThreadCompletion(m_databaseLoaderThread, 0);
-    
-    m_startedLoadingDatabase = false;
-    m_databaseLoaderThread = 0;
-    
+    waitForLoaderThreadCompletion();
     m_hrtfDatabase.clear();
     
     // Clear out singleton.
@@ -107,10 +101,11 @@
 void HRTFDatabaseLoader::loadAsynchronously()
 {
     ASSERT(isMainThread());
+
+    MutexLocker locker(m_threadLock);
     
-    if (!m_hrtfDatabase.get() && !m_startedLoadingDatabase) {
+    if (!m_hrtfDatabase.get() && !m_databaseLoaderThread) {
         // Start the asynchronous database loading process.
-        m_startedLoadingDatabase = true;
         m_databaseLoaderThread = createThread(databaseLoaderEntry, this, "HRTF database loader");
     }
 }
@@ -120,12 +115,14 @@
     return m_hrtfDatabase.get();
 }
 
-
 void HRTFDatabaseLoader::waitForLoaderThreadCompletion()
 {
-    ASSERT(!isMainThread());
-    ASSERT(m_databaseLoaderThread);
-    waitForThreadCompletion(m_databaseLoaderThread, 0);    
+    MutexLocker locker(m_threadLock);
+    
+    // waitForThreadCompletion() should not be called twice for the same thread.
+    if (m_databaseLoaderThread)
+        waitForThreadCompletion(m_databaseLoaderThread, 0);
+    m_databaseLoaderThread = 0;
 }
 
 HRTFDatabase* HRTFDatabaseLoader::defaultHRTFDatabase()

Modified: trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.h (94892 => 94893)


--- trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.h	2011-09-10 00:57:43 UTC (rev 94892)
+++ trunk/Source/WebCore/platform/audio/HRTFDatabaseLoader.h	2011-09-10 00:59:43 UTC (rev 94893)
@@ -55,8 +55,7 @@
     // Returns true once the default database has been completely loaded.
     bool isLoaded() const;
 
-    // May not be called on the main thread.
-    // This is so a different background thread may synchronize with the loader thread.
+    // waitForLoaderThreadCompletion() may be called more than once and is thread-safe.
     void waitForLoaderThreadCompletion();
     
     HRTFDatabase* database() { return m_hrtfDatabase.get(); }
@@ -81,12 +80,14 @@
 
     static HRTFDatabaseLoader* s_loader; // singleton
     OwnPtr<HRTFDatabase> m_hrtfDatabase;
+
+    // Holding a m_threadLock is required when accessing m_databaseLoaderThread.
+    Mutex m_threadLock;
     ThreadIdentifier m_databaseLoaderThread;
-    bool m_startedLoadingDatabase;
+
     double m_databaseSampleRate;    
 };
 
-
 } // namespace WebCore
 
 #endif // HRTFDatabaseLoader_h
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to