Title: [201518] trunk/Source
Revision
201518
Author
beid...@apple.com
Date
2016-05-31 12:33:22 -0700 (Tue, 31 May 2016)

Log Message

Make createCrossThreadTask() functions return on the stack instead of the heap.
https://bugs.webkit.org/show_bug.cgi?id=158215

Reviewed by Darin Adler.

Source/WebCore:

No new tests (Refactor, no change in behavior).

* Modules/indexeddb/client/IDBConnectionProxy.h:

* Modules/indexeddb/server/IDBServer.cpp:
(WebCore::IDBServer::IDBServer::postDatabaseTask):
(WebCore::IDBServer::IDBServer::postDatabaseTaskReply):
(WebCore::IDBServer::IDBServer::databaseRunLoop):
* Modules/indexeddb/server/IDBServer.h:

* Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::postDatabaseTask):
(WebCore::IDBServer::UniqueIDBDatabase::postDatabaseTaskReply):
* Modules/indexeddb/server/UniqueIDBDatabase.h:

* dom/ScriptExecutionContext.h:
(WebCore::ScriptExecutionContext::postCrossThreadTask):

* fileapi/ThreadableBlobRegistry.cpp:
(WebCore::threadableQueue):

Source/WebKit2:

* DatabaseProcess/DatabaseProcess.cpp:
(WebKit::DatabaseProcess::postDatabaseTask):
(WebKit::DatabaseProcess::performNextDatabaseTask):
(WebKit::DatabaseProcess::fetchWebsiteData):
* DatabaseProcess/DatabaseProcess.h:

Source/WTF:

* WTF.xcodeproj/project.pbxproj:

* wtf/CrossThreadCopier.cpp:

* wtf/CrossThreadQueue.h: Added. A lightweight of MessageQueue that deals directly
  in objects instead of in std::unique_ptrs.
(WTF::CrossThreadQueue::isKilled):
(WTF::CrossThreadQueue<DataType>::append):
(WTF::CrossThreadQueue<DataType>::waitForMessage):
(WTF::CrossThreadQueue<DataType>::tryGetMessage):

* wtf/CrossThreadTask.h:
(WTF::createCrossThreadTask):
(WTF::CrossThreadTask::CrossThreadTask): Deleted.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (201517 => 201518)


--- trunk/Source/WTF/ChangeLog	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WTF/ChangeLog	2016-05-31 19:33:22 UTC (rev 201518)
@@ -1,3 +1,25 @@
+2016-05-31  Brady Eidson  <beid...@apple.com>
+
+        Make createCrossThreadTask() functions return on the stack instead of the heap.
+        https://bugs.webkit.org/show_bug.cgi?id=158215
+
+        Reviewed by Darin Adler.
+
+        * WTF.xcodeproj/project.pbxproj:
+
+        * wtf/CrossThreadCopier.cpp:
+
+        * wtf/CrossThreadQueue.h: Added. A lightweight of MessageQueue that deals directly
+          in objects instead of in std::unique_ptrs.
+        (WTF::CrossThreadQueue::isKilled):
+        (WTF::CrossThreadQueue<DataType>::append):
+        (WTF::CrossThreadQueue<DataType>::waitForMessage):
+        (WTF::CrossThreadQueue<DataType>::tryGetMessage):
+
+        * wtf/CrossThreadTask.h:
+        (WTF::createCrossThreadTask):
+        (WTF::CrossThreadTask::CrossThreadTask): Deleted.
+
 2016-05-30  Brady Eidson  <beid...@apple.com>
 
         Move CrossThreadCopier/CrossThreadTask to WTF.

Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (201517 => 201518)


--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj	2016-05-31 19:33:22 UTC (rev 201518)
@@ -104,6 +104,7 @@
 		515F794E1CFC9F4A00CCED93 /* CrossThreadCopier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 515F794B1CFC9F4A00CCED93 /* CrossThreadCopier.cpp */; };
 		515F794F1CFC9F4A00CCED93 /* CrossThreadCopier.h in Headers */ = {isa = PBXBuildFile; fileRef = 515F794C1CFC9F4A00CCED93 /* CrossThreadCopier.h */; };
 		515F79501CFC9F4A00CCED93 /* CrossThreadTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 515F794D1CFC9F4A00CCED93 /* CrossThreadTask.h */; };
+		515F79561CFD3A6900CCED93 /* CrossThreadQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = 515F79551CFD3A6900CCED93 /* CrossThreadQueue.h */; };
 		553071CA1C40427200384898 /* TinyLRUCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 553071C91C40427200384898 /* TinyLRUCache.h */; };
 		70A993FE1AD7151300FA615B /* SymbolRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 70A993FC1AD7151300FA615B /* SymbolRegistry.cpp */; };
 		70A993FF1AD7151300FA615B /* SymbolRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 70A993FD1AD7151300FA615B /* SymbolRegistry.h */; };
@@ -426,6 +427,7 @@
 		515F794B1CFC9F4A00CCED93 /* CrossThreadCopier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CrossThreadCopier.cpp; sourceTree = "<group>"; };
 		515F794C1CFC9F4A00CCED93 /* CrossThreadCopier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossThreadCopier.h; sourceTree = "<group>"; };
 		515F794D1CFC9F4A00CCED93 /* CrossThreadTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossThreadTask.h; sourceTree = "<group>"; };
+		515F79551CFD3A6900CCED93 /* CrossThreadQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CrossThreadQueue.h; sourceTree = "<group>"; };
 		553071C91C40427200384898 /* TinyLRUCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TinyLRUCache.h; sourceTree = "<group>"; };
 		5D247B6214689B8600E78B76 /* libWTF.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libWTF.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		5D247B6E14689C4700E78B76 /* Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; };
@@ -805,6 +807,7 @@
 				0FDB698D1B7C643A000C1078 /* Condition.h */,
 				515F794B1CFC9F4A00CCED93 /* CrossThreadCopier.cpp */,
 				515F794C1CFC9F4A00CCED93 /* CrossThreadCopier.h */,
+				515F79551CFD3A6900CCED93 /* CrossThreadQueue.h */,
 				515F794D1CFC9F4A00CCED93 /* CrossThreadTask.h */,
 				A8A47273151A825A004123FF /* CryptographicallyRandomNumber.cpp */,
 				A8A47274151A825A004123FF /* CryptographicallyRandomNumber.h */,
@@ -1182,6 +1185,7 @@
 				A8A47452151A825B004123FF /* BinarySemaphore.h in Headers */,
 				A8A4738A151A825B004123FF /* Bitmap.h in Headers */,
 				A8A4738C151A825B004123FF /* BitVector.h in Headers */,
+				515F79561CFD3A6900CCED93 /* CrossThreadQueue.h in Headers */,
 				1A944F471C3D8814005BD28C /* BlockPtr.h in Headers */,
 				93DDE9321CDC052D00FD3491 /* dyldSPI.h in Headers */,
 				A8A4738E151A825B004123FF /* BlockStack.h in Headers */,

Modified: trunk/Source/WTF/wtf/CrossThreadCopier.cpp (201517 => 201518)


--- trunk/Source/WTF/wtf/CrossThreadCopier.cpp	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WTF/wtf/CrossThreadCopier.cpp	2016-05-31 19:33:22 UTC (rev 201518)
@@ -30,8 +30,10 @@
  */
 
 #include "config.h"
-#include "CrossThreadCopier.h"
+#include <wtf/CrossThreadCopier.h>
 
+#include <wtf/CrossThreadTask.h>
+
 namespace WTF {
 
 // Test CrossThreadCopier using COMPILE_ASSERT.
@@ -78,3 +80,4 @@
 static_assert((std::is_same<int, CrossThreadCopier<CopierRefCountedTest*>::Type>::value), "CrossThreadCopier specialization improperly applied to raw pointer of a RefCounted (but not ThreadSafeRefCounted) type");
 
 } // namespace WTF
+

Added: trunk/Source/WTF/wtf/CrossThreadQueue.h (0 => 201518)


--- trunk/Source/WTF/wtf/CrossThreadQueue.h	                        (rev 0)
+++ trunk/Source/WTF/wtf/CrossThreadQueue.h	2016-05-31 19:33:22 UTC (rev 201518)
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <limits>
+#include <wtf/Assertions.h>
+#include <wtf/Condition.h>
+#include <wtf/Deque.h>
+#include <wtf/Lock.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/Optional.h>
+#include <wtf/Threading.h>
+
+namespace WTF {
+
+template<typename DataType>
+class CrossThreadQueue {
+    WTF_MAKE_NONCOPYABLE(CrossThreadQueue);
+public:
+    CrossThreadQueue() = default;
+
+    void append(DataType&&);
+
+    DataType waitForMessage();
+    Optional<DataType> tryGetMessage();
+
+    bool isKilled() const { return false; }
+
+private:
+    mutable Lock m_lock;
+    Condition m_condition;
+    Deque<DataType> m_queue;
+};
+
+template<typename DataType>
+void CrossThreadQueue<DataType>::append(DataType&& message)
+{
+    LockHolder lock(m_lock);
+    m_queue.append(WTFMove(message));
+    m_condition.notifyOne();
+}
+
+template<typename DataType>
+DataType CrossThreadQueue<DataType>::waitForMessage()
+{
+    LockHolder lock(m_lock);
+
+    auto found = m_queue.end();
+    while (found == m_queue.end()) {
+        found = m_queue.begin();
+        if (found != m_queue.end())
+            break;
+
+        static const double infiniteTime = std::numeric_limits<double>::max();
+        m_condition.waitUntilWallClockSeconds(m_lock, infiniteTime);
+    }
+
+    return m_queue.takeFirst();
+}
+
+template<typename DataType>
+Optional<DataType> CrossThreadQueue<DataType>::tryGetMessage()
+{
+    LockHolder lock(m_lock);
+
+    if (m_queue.isEmpty())
+        return { };
+
+    return m_queue.takeFirst();
+}
+
+} // namespace WTF
+
+using WTF::CrossThreadQueue;

Modified: trunk/Source/WTF/wtf/CrossThreadTask.h (201517 => 201518)


--- trunk/Source/WTF/wtf/CrossThreadTask.h	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WTF/wtf/CrossThreadTask.h	2016-05-31 19:33:22 UTC (rev 201518)
@@ -27,12 +27,14 @@
 
 #include <wtf/CrossThreadCopier.h>
 #include <wtf/NoncopyableFunction.h>
+#include <wtf/StdLibExtras.h>
 
 namespace WTF {
 
 class CrossThreadTask {
-    WTF_MAKE_NONCOPYABLE(CrossThreadTask);
 public:
+    CrossThreadTask() = default;
+
     CrossThreadTask(NoncopyableFunction<void ()>&& taskFunction)
         : m_taskFunction(WTFMove(taskFunction))
     {
@@ -45,8 +47,6 @@
     }
 
 protected:
-    CrossThreadTask() { }
-
     NoncopyableFunction<void ()> m_taskFunction;
 };
 
@@ -73,33 +73,33 @@
 };
 
 template<typename T>
-std::unique_ptr<CrossThreadTask> createCrossThreadTask(
+CrossThreadTask createCrossThreadTask(
     T& callee,
     void (T::*method)())
 {
-    return std::make_unique<CrossThreadTaskImpl<T>>(&callee, method);
+    return CrossThreadTaskImpl<T>(&callee, method);
 }
 
 template<typename T, typename P1, typename MP1>
-std::unique_ptr<CrossThreadTask> createCrossThreadTask(
+CrossThreadTask createCrossThreadTask(
     T& callee,
     void (T::*method)(MP1),
     const P1& parameter1)
 {
-    return std::make_unique<CrossThreadTaskImpl<T, MP1>>(
+    return CrossThreadTaskImpl<T, MP1>(
         &callee,
         method,
         WTF::CrossThreadCopier<P1>::copy(parameter1));
 }
 
 template<typename T, typename P1, typename MP1, typename P2, typename MP2>
-std::unique_ptr<CrossThreadTask> createCrossThreadTask(
+CrossThreadTask createCrossThreadTask(
     T& callee,
     void (T::*method)(MP1, MP2),
     const P1& parameter1,
     const P2& parameter2)
 {
-    return std::make_unique<CrossThreadTaskImpl<T, MP1, MP2>>(
+    return CrossThreadTaskImpl<T, MP1, MP2>(
         &callee,
         method,
         WTF::CrossThreadCopier<P1>::copy(parameter1),
@@ -108,14 +108,14 @@
 }
 
 template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3>
-std::unique_ptr<CrossThreadTask> createCrossThreadTask(
+CrossThreadTask createCrossThreadTask(
     T& callee,
     void (T::*method)(MP1, MP2, MP3),
     const P1& parameter1,
     const P2& parameter2,
     const P3& parameter3)
 {
-    return std::make_unique<CrossThreadTaskImpl<T, MP1, MP2, MP3>>(
+    return CrossThreadTaskImpl<T, MP1, MP2, MP3>(
         &callee,
         method,
         WTF::CrossThreadCopier<P1>::copy(parameter1),
@@ -124,13 +124,13 @@
 }
 
 template<typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3>
-std::unique_ptr<CrossThreadTask> createCrossThreadTask(
+CrossThreadTask createCrossThreadTask(
     void (*method)(MP1, MP2, MP3),
     const P1& parameter1,
     const P2& parameter2,
     const P3& parameter3)
 {
-    return std::make_unique<CrossThreadTaskStaticImpl<MP1, MP2, MP3>>(
+    return CrossThreadTaskStaticImpl<MP1, MP2, MP3>(
         method,
         WTF::CrossThreadCopier<P1>::copy(parameter1),
         WTF::CrossThreadCopier<P2>::copy(parameter2),
@@ -138,7 +138,7 @@
 }
 
 template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4>
-std::unique_ptr<CrossThreadTask> createCrossThreadTask(
+CrossThreadTask createCrossThreadTask(
     T& callee,
     void (T::*method)(MP1, MP2, MP3, MP4),
     const P1& parameter1,
@@ -146,7 +146,7 @@
     const P3& parameter3,
     const P4& parameter4)
 {
-    return std::make_unique<CrossThreadTaskImpl<T, MP1, MP2, MP3, MP4>>(
+    return CrossThreadTaskImpl<T, MP1, MP2, MP3, MP4>(
         &callee,
         method,
         WTF::CrossThreadCopier<P1>::copy(parameter1),
@@ -156,7 +156,7 @@
 }
 
 template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5>
-std::unique_ptr<CrossThreadTask> createCrossThreadTask(
+CrossThreadTask createCrossThreadTask(
     T& callee,
     void (T::*method)(MP1, MP2, MP3, MP4, MP5),
     const P1& parameter1,
@@ -165,7 +165,7 @@
     const P4& parameter4,
     const P5& parameter5)
 {
-    return std::make_unique<CrossThreadTaskImpl<T, MP1, MP2, MP3, MP4, MP5>>(
+    return CrossThreadTaskImpl<T, MP1, MP2, MP3, MP4, MP5>(
         &callee,
         method,
         WTF::CrossThreadCopier<P1>::copy(parameter1),
@@ -176,7 +176,7 @@
 }
 
 template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6>
-std::unique_ptr<CrossThreadTask> createCrossThreadTask(
+CrossThreadTask createCrossThreadTask(
     T& callee,
     void (T::*method)(MP1, MP2, MP3, MP4, MP5, MP6),
     const P1& parameter1,
@@ -186,7 +186,7 @@
     const P5& parameter5,
     const P6& parameter6)
 {
-    return std::make_unique<CrossThreadTaskImpl<T, MP1, MP2, MP3, MP4, MP5, MP6>>(
+    return CrossThreadTaskImpl<T, MP1, MP2, MP3, MP4, MP5, MP6>(
         &callee,
         method,
         WTF::CrossThreadCopier<P1>::copy(parameter1),
@@ -198,7 +198,7 @@
 }
 
 template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6, typename P7, typename MP7>
-std::unique_ptr<CrossThreadTask> createCrossThreadTask(
+CrossThreadTask createCrossThreadTask(
     T& callee,
     void (T::*method)(MP1, MP2, MP3, MP4, MP5, MP6, MP7),
     const P1& parameter1,
@@ -209,7 +209,7 @@
     const P6& parameter6,
     const P7& parameter7)
 {
-    return std::make_unique<CrossThreadTaskImpl<T, MP1, MP2, MP3, MP4, MP5, MP6, MP7>>(
+    return CrossThreadTaskImpl<T, MP1, MP2, MP3, MP4, MP5, MP6, MP7>(
         &callee,
         method,
         WTF::CrossThreadCopier<P1>::copy(parameter1),
@@ -222,7 +222,7 @@
 }
 
 template<typename T, typename P1, typename MP1, typename P2, typename MP2, typename P3, typename MP3, typename P4, typename MP4, typename P5, typename MP5, typename P6, typename MP6, typename P7, typename MP7, typename P8, typename MP8>
-std::unique_ptr<CrossThreadTask> createCrossThreadTask(
+CrossThreadTask createCrossThreadTask(
     T& callee,
     void (T::*method)(MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8),
     const P1& parameter1,
@@ -234,7 +234,7 @@
     const P7& parameter7,
     const P8& parameter8)
 {
-    return std::make_unique<CrossThreadTaskImpl<T, MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8>>(
+    return CrossThreadTaskImpl<T, MP1, MP2, MP3, MP4, MP5, MP6, MP7, MP8>(
         &callee,
         method,
         WTF::CrossThreadCopier<P1>::copy(parameter1),

Modified: trunk/Source/WebCore/ChangeLog (201517 => 201518)


--- trunk/Source/WebCore/ChangeLog	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WebCore/ChangeLog	2016-05-31 19:33:22 UTC (rev 201518)
@@ -1,3 +1,31 @@
+2016-05-31  Brady Eidson  <beid...@apple.com>
+
+        Make createCrossThreadTask() functions return on the stack instead of the heap.
+        https://bugs.webkit.org/show_bug.cgi?id=158215
+
+        Reviewed by Darin Adler.
+
+        No new tests (Refactor, no change in behavior).
+
+        * Modules/indexeddb/client/IDBConnectionProxy.h:
+        
+        * Modules/indexeddb/server/IDBServer.cpp:
+        (WebCore::IDBServer::IDBServer::postDatabaseTask):
+        (WebCore::IDBServer::IDBServer::postDatabaseTaskReply):
+        (WebCore::IDBServer::IDBServer::databaseRunLoop):
+        * Modules/indexeddb/server/IDBServer.h:
+        
+        * Modules/indexeddb/server/UniqueIDBDatabase.cpp:
+        (WebCore::IDBServer::UniqueIDBDatabase::postDatabaseTask):
+        (WebCore::IDBServer::UniqueIDBDatabase::postDatabaseTaskReply):
+        * Modules/indexeddb/server/UniqueIDBDatabase.h:
+        
+        * dom/ScriptExecutionContext.h:
+        (WebCore::ScriptExecutionContext::postCrossThreadTask):
+        
+        * fileapi/ThreadableBlobRegistry.cpp:
+        (WebCore::threadableQueue):
+
 2016-05-31  Dave Hyatt  <hy...@apple.com>
 
         REGRESSION (r189567): Elements with aspect ratios not handled correctly inside flexbox.

Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionProxy.h (201517 => 201518)


--- trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionProxy.h	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionProxy.h	2016-05-31 19:33:22 UTC (rev 201518)
@@ -31,6 +31,7 @@
 #include "IDBResourceIdentifier.h"
 #include "TransactionOperation.h"
 #include <functional>
+#include <wtf/CrossThreadQueue.h>
 #include <wtf/CrossThreadTask.h>
 #include <wtf/HashMap.h>
 #include <wtf/MainThread.h>
@@ -157,7 +158,7 @@
     HashMap<IDBResourceIdentifier, RefPtr<TransactionOperation>> m_activeOperations;
     Lock m_transactionOperationLock;
 
-    MessageQueue<CrossThreadTask> m_mainThreadQueue;
+    CrossThreadQueue<CrossThreadTask> m_mainThreadQueue;
     Lock m_mainThreadTaskLock;
     RefPtr<IDBConnectionToServer> m_mainThreadProtector;
 };

Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp (201517 => 201518)


--- trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.cpp	2016-05-31 19:33:22 UTC (rev 201518)
@@ -431,13 +431,13 @@
     connection->didGetAllDatabaseNames(callbackID, databaseNames);
 }
 
-void IDBServer::postDatabaseTask(std::unique_ptr<CrossThreadTask>&& task)
+void IDBServer::postDatabaseTask(CrossThreadTask&& task)
 {
     ASSERT(isMainThread());
     m_databaseQueue.append(WTFMove(task));
 }
 
-void IDBServer::postDatabaseTaskReply(std::unique_ptr<CrossThreadTask>&& task)
+void IDBServer::postDatabaseTaskReply(CrossThreadTask&& task)
 {
     ASSERT(!isMainThread());
     m_databaseReplyQueue.append(WTFMove(task));
@@ -467,8 +467,8 @@
         Locker<Lock> locker(m_databaseThreadCreationLock);
     }
 
-    while (auto task = m_databaseQueue.waitForMessage())
-        task->performTask();
+    while (!m_databaseQueue.isKilled())
+        m_databaseQueue.waitForMessage().performTask();
 }
 
 void IDBServer::handleTaskRepliesOnMainThread()

Modified: trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h (201517 => 201518)


--- trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WebCore/Modules/indexeddb/server/IDBServer.h	2016-05-31 19:33:22 UTC (rev 201518)
@@ -31,6 +31,7 @@
 #include "IDBDatabaseIdentifier.h"
 #include "UniqueIDBDatabase.h"
 #include "UniqueIDBDatabaseConnection.h"
+#include <wtf/CrossThreadQueue.h>
 #include <wtf/CrossThreadTask.h>
 #include <wtf/HashMap.h>
 #include <wtf/Lock.h>
@@ -84,8 +85,8 @@
 
     WEBCORE_EXPORT void getAllDatabaseNames(uint64_t serverConnectionIdentifier, const SecurityOriginData& mainFrameOrigin, const SecurityOriginData& openingOrigin, uint64_t callbackID);
 
-    void postDatabaseTask(std::unique_ptr<CrossThreadTask>&&);
-    void postDatabaseTaskReply(std::unique_ptr<CrossThreadTask>&&);
+    void postDatabaseTask(CrossThreadTask&&);
+    void postDatabaseTaskReply(CrossThreadTask&&);
 
     void registerDatabaseConnection(UniqueIDBDatabaseConnection&);
     void unregisterDatabaseConnection(UniqueIDBDatabaseConnection&);
@@ -124,8 +125,8 @@
     Lock m_mainThreadReplyLock;
     bool m_mainThreadReplyScheduled { false };
 
-    MessageQueue<CrossThreadTask> m_databaseQueue;
-    MessageQueue<CrossThreadTask> m_databaseReplyQueue;
+    CrossThreadQueue<CrossThreadTask> m_databaseQueue;
+    CrossThreadQueue<CrossThreadTask> m_databaseReplyQueue;
 
     HashMap<uint64_t, UniqueIDBDatabaseConnection*> m_databaseConnections;
     HashMap<IDBResourceIdentifier, UniqueIDBDatabaseTransaction*> m_transactions;

Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp (201517 => 201518)


--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp	2016-05-31 19:33:22 UTC (rev 201518)
@@ -1505,7 +1505,7 @@
         invokeOperationAndTransactionTimer();
 }
 
-void UniqueIDBDatabase::postDatabaseTask(std::unique_ptr<CrossThreadTask>&& task)
+void UniqueIDBDatabase::postDatabaseTask(CrossThreadTask&& task)
 {
     ASSERT(isMainThread());
     m_databaseQueue.append(WTFMove(task));
@@ -1514,7 +1514,7 @@
     m_server.postDatabaseTask(createCrossThreadTask(*this, &UniqueIDBDatabase::executeNextDatabaseTask));
 }
 
-void UniqueIDBDatabase::postDatabaseTaskReply(std::unique_ptr<CrossThreadTask>&& task)
+void UniqueIDBDatabase::postDatabaseTaskReply(CrossThreadTask&& task)
 {
     ASSERT(!isMainThread());
     m_databaseReplyQueue.append(WTFMove(task));

Modified: trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h (201517 => 201518)


--- trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h	2016-05-31 19:33:22 UTC (rev 201518)
@@ -37,6 +37,7 @@
 #include "Timer.h"
 #include "UniqueIDBDatabaseConnection.h"
 #include "UniqueIDBDatabaseTransaction.h"
+#include <wtf/CrossThreadQueue.h>
 #include <wtf/CrossThreadTask.h>
 #include <wtf/Deque.h>
 #include <wtf/HashCountedSet.h>
@@ -195,8 +196,8 @@
 
     bool prepareToFinishTransaction(UniqueIDBDatabaseTransaction&);
 
-    void postDatabaseTask(std::unique_ptr<CrossThreadTask>&&);
-    void postDatabaseTaskReply(std::unique_ptr<CrossThreadTask>&&);
+    void postDatabaseTask(CrossThreadTask&&);
+    void postDatabaseTaskReply(CrossThreadTask&&);
     void executeNextDatabaseTask();
     void executeNextDatabaseTaskReply();
 
@@ -242,8 +243,8 @@
 
     bool m_deleteBackingStoreInProgress { false };
 
-    MessageQueue<CrossThreadTask> m_databaseQueue;
-    MessageQueue<CrossThreadTask> m_databaseReplyQueue;
+    CrossThreadQueue<CrossThreadTask> m_databaseQueue;
+    CrossThreadQueue<CrossThreadTask> m_databaseReplyQueue;
     std::atomic<uint64_t> m_queuedTaskCount { 0 };
 
     bool m_hardClosedForUserDelete { false };

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (201517 => 201518)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2016-05-31 19:33:22 UTC (rev 201518)
@@ -172,11 +172,8 @@
     template<typename... Arguments>
     void postCrossThreadTask(Arguments&&... arguments)
     {
-        auto crossThreadTask = createCrossThreadTask(arguments...);
-        auto* rawTask = crossThreadTask.release();
-        postTask([=](ScriptExecutionContext&) {
-            std::unique_ptr<CrossThreadTask> task(rawTask);
-            task->performTask();
+        postTask([crossThreadTask = createCrossThreadTask(arguments...)](ScriptExecutionContext&) mutable {
+            crossThreadTask.performTask();
         });
     }
 

Modified: trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp (201517 => 201518)


--- trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp	2016-05-31 19:33:22 UTC (rev 201518)
@@ -37,6 +37,7 @@
 #include "BlobURL.h"
 #include "SecurityOrigin.h"
 #include <mutex>
+#include <wtf/CrossThreadQueue.h>
 #include <wtf/CrossThreadTask.h>
 #include <wtf/HashMap.h>
 #include <wtf/MainThread.h>
@@ -100,12 +101,12 @@
     return *map;
 }
 
-static MessageQueue<CrossThreadTask>& threadableQueue()
+static CrossThreadQueue<CrossThreadTask>& threadableQueue()
 {
     static std::once_flag onceFlag;
-    static MessageQueue<CrossThreadTask>* queue;
+    static CrossThreadQueue<CrossThreadTask>* queue;
     std::call_once(onceFlag, [] {
-        queue = new MessageQueue<CrossThreadTask>;
+        queue = new CrossThreadQueue<CrossThreadTask>;
     });
 
     return *queue;

Modified: trunk/Source/WebKit2/ChangeLog (201517 => 201518)


--- trunk/Source/WebKit2/ChangeLog	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WebKit2/ChangeLog	2016-05-31 19:33:22 UTC (rev 201518)
@@ -1,3 +1,16 @@
+2016-05-31  Brady Eidson  <beid...@apple.com>
+
+        Make createCrossThreadTask() functions return on the stack instead of the heap.
+        https://bugs.webkit.org/show_bug.cgi?id=158215
+
+        Reviewed by Darin Adler.
+
+        * DatabaseProcess/DatabaseProcess.cpp:
+        (WebKit::DatabaseProcess::postDatabaseTask):
+        (WebKit::DatabaseProcess::performNextDatabaseTask):
+        (WebKit::DatabaseProcess::fetchWebsiteData):
+        * DatabaseProcess/DatabaseProcess.h:
+
 2016-05-31  Carlos Garcia Campos  <cgar...@igalia.com>
 
         Unreviewed. Update OptionsGTK.cmake and NEWS for 2.13.1 release.

Modified: trunk/Source/WebKit2/DatabaseProcess/DatabaseProcess.cpp (201517 => 201518)


--- trunk/Source/WebKit2/DatabaseProcess/DatabaseProcess.cpp	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WebKit2/DatabaseProcess/DatabaseProcess.cpp	2016-05-31 19:33:22 UTC (rev 201518)
@@ -143,7 +143,7 @@
 }
 #endif
 
-void DatabaseProcess::postDatabaseTask(std::unique_ptr<CrossThreadTask> task)
+void DatabaseProcess::postDatabaseTask(CrossThreadTask&& task)
 {
     ASSERT(RunLoop::isMain());
 
@@ -160,14 +160,14 @@
 {
     ASSERT(!RunLoop::isMain());
 
-    std::unique_ptr<CrossThreadTask> task;
+    CrossThreadTask task;
     {
         LockHolder locker(m_databaseTaskMutex);
         ASSERT(!m_databaseTasks.isEmpty());
         task = m_databaseTasks.takeFirst();
     }
 
-    task->performTask();
+    task.performTask();
 }
 
 void DatabaseProcess::createDatabaseToWebProcessConnection()
@@ -223,7 +223,7 @@
 #if ENABLE(INDEXED_DATABASE)
     if (websiteDataTypes.contains(WebsiteDataType::IndexedDBDatabases)) {
         // FIXME: Pick the right database store based on the session ID.
-        postDatabaseTask(std::make_unique<CrossThreadTask>([callbackAggregator, websiteDataTypes, this] {
+        postDatabaseTask(CrossThreadTask([callbackAggregator, websiteDataTypes, this] {
 
             Vector<RefPtr<SecurityOrigin>> securityOrigins = indexedDatabaseOrigins();
 

Modified: trunk/Source/WebKit2/DatabaseProcess/DatabaseProcess.h (201517 => 201518)


--- trunk/Source/WebKit2/DatabaseProcess/DatabaseProcess.h	2016-05-31 18:49:52 UTC (rev 201517)
+++ trunk/Source/WebKit2/DatabaseProcess/DatabaseProcess.h	2016-05-31 19:33:22 UTC (rev 201518)
@@ -68,7 +68,7 @@
 
     WorkQueue& queue() { return m_queue.get(); }
 
-    void postDatabaseTask(std::unique_ptr<CrossThreadTask>);
+    void postDatabaseTask(CrossThreadTask&&);
 
 #if ENABLE(INDEXED_DATABASE)
     // WebCore::IDBServer::IDBBackingStoreFileHandler
@@ -126,7 +126,7 @@
     HashMap<String, RefPtr<SandboxExtension>> m_blobTemporaryFileSandboxExtensions;
     HashMap<uint64_t, std::function<void (const SandboxExtension::HandleArray&)>> m_sandboxExtensionForBlobsCompletionHandlers;
 
-    Deque<std::unique_ptr<CrossThreadTask>> m_databaseTasks;
+    Deque<CrossThreadTask> m_databaseTasks;
     Lock m_databaseTaskMutex;
 };
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to