<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[50521] trunk/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/50521">50521</a></dd>
<dt>Author</dt> <dd>jorlow@chromium.org</dd>
<dt>Date</dt> <dd>2009-11-04 11:35:04 -0800 (Wed, 04 Nov 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Revert 50519 while I work out what went wrong.

Patch by Jeremy Orlow &lt;jorlow@chromium.org&gt; on 2009-11-04
* storage/LocalStorageThread.cpp:
(WebCore::LocalStorageThread::create):
(WebCore::LocalStorageThread::LocalStorageThread):
(WebCore::LocalStorageThread::start):
(WebCore::LocalStorageThread::localStorageThreadStart):
(WebCore::LocalStorageThread::localStorageThread):
(WebCore::LocalStorageThread::scheduleImport):
(WebCore::LocalStorageThread::scheduleSync):
(WebCore::LocalStorageThread::terminate):
(WebCore::LocalStorageThread::performTerminate):
* storage/LocalStorageThread.h:
* storage/StorageSyncManager.cpp:
(WebCore::StorageSyncManager::StorageSyncManager):
(WebCore::StorageSyncManager::~StorageSyncManager):
(WebCore::StorageSyncManager::scheduleImport):
(WebCore::StorageSyncManager::scheduleSync):
* storage/StorageSyncManager.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebCoreChangeLog">trunk/WebCore/ChangeLog</a></li>
<li><a href="#trunkWebCorestorageLocalStorageThreadcpp">trunk/WebCore/storage/LocalStorageThread.cpp</a></li>
<li><a href="#trunkWebCorestorageLocalStorageThreadh">trunk/WebCore/storage/LocalStorageThread.h</a></li>
<li><a href="#trunkWebCorestorageStorageSyncManagercpp">trunk/WebCore/storage/StorageSyncManager.cpp</a></li>
<li><a href="#trunkWebCorestorageStorageSyncManagerh">trunk/WebCore/storage/StorageSyncManager.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/ChangeLog (50520 => 50521)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/ChangeLog        2009-11-04 19:32:05 UTC (rev 50520)
+++ trunk/WebCore/ChangeLog        2009-11-04 19:35:04 UTC (rev 50521)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2009-11-04  Jeremy Orlow  &lt;jorlow@chromium.org&gt;
+
+        Revert 50519 while I work out what went wrong.
+
+        * storage/LocalStorageThread.cpp:
+        (WebCore::LocalStorageThread::create):
+        (WebCore::LocalStorageThread::LocalStorageThread):
+        (WebCore::LocalStorageThread::start):
+        (WebCore::LocalStorageThread::localStorageThreadStart):
+        (WebCore::LocalStorageThread::localStorageThread):
+        (WebCore::LocalStorageThread::scheduleImport):
+        (WebCore::LocalStorageThread::scheduleSync):
+        (WebCore::LocalStorageThread::terminate):
+        (WebCore::LocalStorageThread::performTerminate):
+        * storage/LocalStorageThread.h:
+        * storage/StorageSyncManager.cpp:
+        (WebCore::StorageSyncManager::StorageSyncManager):
+        (WebCore::StorageSyncManager::~StorageSyncManager):
+        (WebCore::StorageSyncManager::scheduleImport):
+        (WebCore::StorageSyncManager::scheduleSync):
+        * storage/StorageSyncManager.h:
+
</ins><span class="cx"> 2009-11-04  Pavel Feldman  &lt;pfeldman@chromium.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Timothy Hatcher.
</span></span></pre></div>
<a id="trunkWebCorestorageLocalStorageThreadcpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/storage/LocalStorageThread.cpp (50520 => 50521)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/storage/LocalStorageThread.cpp        2009-11-04 19:32:05 UTC (rev 50520)
+++ trunk/WebCore/storage/LocalStorageThread.cpp        2009-11-04 19:35:04 UTC (rev 50521)
</span><span class="lines">@@ -33,70 +33,93 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-PassOwnPtr&lt;LocalStorageThread&gt; LocalStorageThread::create()
</del><ins>+PassRefPtr&lt;LocalStorageThread&gt; LocalStorageThread::create()
</ins><span class="cx"> {
</span><del>-    return new LocalStorageThread;
</del><ins>+    return adoptRef(new LocalStorageThread);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> LocalStorageThread::LocalStorageThread()
</span><span class="cx">     : m_threadID(0)
</span><ins>+    , m_terminated(false)
</ins><span class="cx"> {
</span><ins>+    m_selfRef = this;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-LocalStorageThread::~LocalStorageThread()
</del><ins>+bool LocalStorageThread::start()
</ins><span class="cx"> {
</span><del>-    ASSERT(isMainThread());
-    ASSERT(!m_threadID);
-}
</del><ins>+    MutexLocker lock(m_threadCreationMutex);
</ins><span class="cx"> 
</span><del>-bool LocalStorageThread::start()
-{
-    ASSERT(isMainThread());
-    if (!m_threadID)
-        m_threadID = createThread(LocalStorageThread::threadEntryPointCallback, this, &quot;WebCore: LocalStorage&quot;);
</del><ins>+    if (m_threadID)
+        return true;
+
+    m_threadID = createThread(LocalStorageThread::localStorageThreadStart, this, &quot;WebCore: LocalStorage&quot;);
+
</ins><span class="cx">     return m_threadID;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void* LocalStorageThread::threadEntryPointCallback(void* thread)
</del><ins>+void* LocalStorageThread::localStorageThreadStart(void* thread)
</ins><span class="cx"> {
</span><del>-    return static_cast&lt;LocalStorageThread*&gt;(thread)-&gt;threadEntryPoint();
</del><ins>+    return static_cast&lt;LocalStorageThread*&gt;(thread)-&gt;localStorageThread();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void* LocalStorageThread::threadEntryPoint()
</del><ins>+void* LocalStorageThread::localStorageThread()
</ins><span class="cx"> {
</span><del>-    ASSERT(!isMainThread());
</del><ins>+    {
+        // Wait for LocalStorageThread::start() to complete.
+        MutexLocker lock(m_threadCreationMutex);
+    }
+
</ins><span class="cx">     while (OwnPtr&lt;LocalStorageTask&gt; task = m_queue.waitForMessage())
</span><span class="cx">         task-&gt;performTask();
</span><span class="cx"> 
</span><ins>+    // Detach the thread so its resources are no longer of any concern to anyone else
+    detachThread(m_threadID);
+    m_threadID = 0;
+
+    // Clear the self refptr, possibly resulting in deletion
+    m_selfRef = 0;
+
</ins><span class="cx">     return 0;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void LocalStorageThread::scheduleTask(PassRefPtr&lt;LocalStorageTask&gt; task)
</del><ins>+void LocalStorageThread::scheduleImport(StorageAreaSync* area)
</ins><span class="cx"> {
</span><del>-    ASSERT(isMainThread());
</del><span class="cx">     ASSERT(!m_queue.killed() &amp;&amp; m_threadID);
</span><del>-    m_queue.append(task);
</del><ins>+    m_queue.append(LocalStorageTask::createImport(area));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void LocalStorageThread::scheduleSync(StorageAreaSync* area)
+{
+    ASSERT(!m_queue.killed() &amp;&amp; m_threadID);
+    m_queue.append(LocalStorageTask::createSync(area));
+}
+
</ins><span class="cx"> void LocalStorageThread::terminate()
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isMainThread());
</span><ins>+
+    // Ideally we'd never be killing a thread that wasn't live, so ASSERT it.
+    // But if we do in a release build, make sure to not wait on a condition that will never get signalled
</ins><span class="cx">     ASSERT(!m_queue.killed() &amp;&amp; m_threadID);
</span><del>-    // Even in weird, exceptional cases, don't wait on a nonexistent thread to terminate.
</del><span class="cx">     if (!m_threadID)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    void* returnValue;
</del><span class="cx">     m_queue.append(LocalStorageTask::createTerminate(this));
</span><del>-    waitForThreadCompletion(m_threadID, &amp;returnValue);
-    ASSERT(m_queue.killed());
-    m_threadID = 0;
</del><ins>+
+    MutexLocker locker(m_terminateLock);
+    while (!m_terminated)
+        m_terminateCondition.wait(m_terminateLock);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void LocalStorageThread::performTerminate()
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!isMainThread());
</span><ins>+
</ins><span class="cx">     m_queue.kill();
</span><ins>+
+    MutexLocker locker(m_terminateLock);
+    m_terminated = true;
+    m_terminateCondition.signal();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkWebCorestorageLocalStorageThreadh"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/storage/LocalStorageThread.h (50520 => 50521)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/storage/LocalStorageThread.h        2009-11-04 19:32:05 UTC (rev 50520)
+++ trunk/WebCore/storage/LocalStorageThread.h        2009-11-04 19:35:04 UTC (rev 50521)
</span><span class="lines">@@ -30,7 +30,6 @@
</span><span class="cx"> 
</span><span class="cx"> #include &lt;wtf/HashSet.h&gt;
</span><span class="cx"> #include &lt;wtf/MessageQueue.h&gt;
</span><del>-#include &lt;wtf/PassOwnPtr.h&gt;
</del><span class="cx"> #include &lt;wtf/PassRefPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/Threading.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -40,27 +39,35 @@
</span><span class="cx">     class LocalStorageTask;
</span><span class="cx"> 
</span><span class="cx">     // FIXME: Rename this class to StorageThread
</span><del>-    class LocalStorageThread : public Noncopyable {
</del><ins>+    class LocalStorageThread : public ThreadSafeShared&lt;LocalStorageThread&gt; {
</ins><span class="cx">     public:
</span><del>-        static PassOwnPtr&lt;LocalStorageThread&gt; create();
-        ~LocalStorageThread();
</del><ins>+        static PassRefPtr&lt;LocalStorageThread&gt; create();
</ins><span class="cx"> 
</span><span class="cx">         bool start();
</span><ins>+
+        void scheduleImport(StorageAreaSync*);
+        void scheduleSync(StorageAreaSync*);
+
+        // Called from the main thread to synchronously shut down this thread
</ins><span class="cx">         void terminate();
</span><del>-        void scheduleTask(PassRefPtr&lt;LocalStorageTask&gt;);
-
-        // Background thread part of the terminate procedure.
</del><ins>+        // Background thread part of the terminate procedure
</ins><span class="cx">         void performTerminate();
</span><span class="cx"> 
</span><span class="cx">     private:
</span><span class="cx">         LocalStorageThread();
</span><span class="cx"> 
</span><del>-        // Called on background thread.
-        static void* threadEntryPointCallback(void*);
-        void* threadEntryPoint();
</del><ins>+        static void* localStorageThreadStart(void*);
+        void* localStorageThread();
</ins><span class="cx"> 
</span><ins>+        Mutex m_threadCreationMutex;
</ins><span class="cx">         ThreadIdentifier m_threadID;
</span><ins>+        RefPtr&lt;LocalStorageThread&gt; m_selfRef;
+
</ins><span class="cx">         MessageQueue&lt;LocalStorageTask&gt; m_queue;
</span><ins>+
+        Mutex m_terminateLock;
+        ThreadCondition m_terminateCondition;
+        bool m_terminated;
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkWebCorestorageStorageSyncManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/storage/StorageSyncManager.cpp (50520 => 50521)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/storage/StorageSyncManager.cpp        2009-11-04 19:32:05 UTC (rev 50520)
+++ trunk/WebCore/storage/StorageSyncManager.cpp        2009-11-04 19:35:04 UTC (rev 50521)
</span><span class="lines">@@ -48,21 +48,19 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> StorageSyncManager::StorageSyncManager(const String&amp; path)
</span><del>-    : m_thread(LocalStorageThread::create())
-    , m_path(path.crossThreadString())
</del><ins>+    : m_path(path.crossThreadString())
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(isMainThread());
</span><span class="cx">     ASSERT(!m_path.isEmpty());
</span><ins>+    m_thread = LocalStorageThread::create();
</ins><span class="cx">     m_thread-&gt;start();
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> StorageSyncManager::~StorageSyncManager()
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isMainThread());
</span><del>-    ASSERT(!m_thread);
</del><span class="cx"> }
</span><span class="cx"> 
</span><del>-// Called on a background thread.
</del><span class="cx"> String StorageSyncManager::fullDatabaseFilename(SecurityOrigin* origin)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(origin);
</span><span class="lines">@@ -87,18 +85,19 @@
</span><span class="cx"> bool StorageSyncManager::scheduleImport(PassRefPtr&lt;StorageAreaSync&gt; area)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isMainThread());
</span><del>-    ASSERT(m_thread);
</del><ins>+
</ins><span class="cx">     if (m_thread)
</span><del>-        m_thread-&gt;scheduleTask(LocalStorageTask::createImport(area.get()));
</del><ins>+        m_thread-&gt;scheduleImport(area.get());
+
</ins><span class="cx">     return m_thread;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void StorageSyncManager::scheduleSync(PassRefPtr&lt;StorageAreaSync&gt; area)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isMainThread());
</span><del>-    ASSERT(m_thread);
</del><ins>+
</ins><span class="cx">     if (m_thread)
</span><del>-        m_thread-&gt;scheduleTask(LocalStorageTask::createSync(area.get()));
</del><ins>+        m_thread-&gt;scheduleSync(area.get());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkWebCorestorageStorageSyncManagerh"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/storage/StorageSyncManager.h (50520 => 50521)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/storage/StorageSyncManager.h        2009-11-04 19:32:05 UTC (rev 50520)
+++ trunk/WebCore/storage/StorageSyncManager.h        2009-11-04 19:35:04 UTC (rev 50521)
</span><span class="lines">@@ -32,7 +32,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &lt;wtf/PassRefPtr.h&gt;
</span><span class="cx"> #include &lt;wtf/RefCounted.h&gt;
</span><del>-#include &lt;wtf/OwnPtr.h&gt;
</del><ins>+#include &lt;wtf/RefPtr.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="lines">@@ -53,7 +53,7 @@
</span><span class="cx">     private:
</span><span class="cx">         StorageSyncManager(const String&amp; path);
</span><span class="cx"> 
</span><del>-        OwnPtr&lt;LocalStorageThread&gt; m_thread;
</del><ins>+        RefPtr&lt;LocalStorageThread&gt; m_thread;
</ins><span class="cx"> 
</span><span class="cx">     // The following members are subject to thread synchronization issues
</span><span class="cx">     public:
</span></span></pre>
</div>
</div>

</body>
</html>