Title: [278544] trunk/Source/WebCore
Revision
278544
Author
cdu...@apple.com
Date
2021-06-06 23:16:22 -0700 (Sun, 06 Jun 2021)

Log Message

Drop MainThreadTaskDispatcher and use callOnMainThread() instead
https://bugs.webkit.org/show_bug.cgi?id=226701

Reviewed by Darin Adler.

Drop MainThreadTaskDispatcher and use callOnMainThread() instead. There is a no need for a
global Timer or a Deque of tasks.

* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/DeferrableTask.h:
(WebCore::MainThreadDeferrableTask::scheduleTask):
* platform/GenericTaskQueue.cpp: Removed.
* platform/GenericTaskQueue.h:
(WebCore::MainThreadTaskQueue::MainThreadTaskQueue):
(WebCore::MainThreadTaskQueue::enqueueTask):

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (278543 => 278544)


--- trunk/Source/WebCore/ChangeLog	2021-06-07 04:22:38 UTC (rev 278543)
+++ trunk/Source/WebCore/ChangeLog	2021-06-07 06:16:22 UTC (rev 278544)
@@ -1,5 +1,24 @@
 2021-06-06  Chris Dumez  <cdu...@apple.com>
 
+        Drop MainThreadTaskDispatcher and use callOnMainThread() instead
+        https://bugs.webkit.org/show_bug.cgi?id=226701
+
+        Reviewed by Darin Adler.
+
+        Drop MainThreadTaskDispatcher and use callOnMainThread() instead. There is a no need for a
+        global Timer or a Deque of tasks.
+
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/DeferrableTask.h:
+        (WebCore::MainThreadDeferrableTask::scheduleTask):
+        * platform/GenericTaskQueue.cpp: Removed.
+        * platform/GenericTaskQueue.h:
+        (WebCore::MainThreadTaskQueue::MainThreadTaskQueue):
+        (WebCore::MainThreadTaskQueue::enqueueTask):
+
+2021-06-06  Chris Dumez  <cdu...@apple.com>
+
         Stop using legacy EventLoopDeferrableTask
         https://bugs.webkit.org/show_bug.cgi?id=226700
 

Modified: trunk/Source/WebCore/Sources.txt (278543 => 278544)


--- trunk/Source/WebCore/Sources.txt	2021-06-07 04:22:38 UTC (rev 278543)
+++ trunk/Source/WebCore/Sources.txt	2021-06-07 06:16:22 UTC (rev 278544)
@@ -1834,7 +1834,6 @@
 platform/FileMonitor.cpp
 platform/FileStream.cpp
 platform/FrameRateMonitor.cpp
-platform/GenericTaskQueue.cpp
 platform/LayoutUnit.cpp
 platform/LegacySchemeRegistry.cpp
 platform/Length.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (278543 => 278544)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-06-07 04:22:38 UTC (rev 278543)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-06-07 06:16:22 UTC (rev 278544)
@@ -14943,7 +14943,6 @@
 		CD3E252118046BCD00E27F56 /* CSSGridTemplateAreasValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSGridTemplateAreasValue.cpp; sourceTree = "<group>"; };
 		CD3E252218046BCD00E27F56 /* CSSGridTemplateAreasValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSGridTemplateAreasValue.h; sourceTree = "<group>"; };
 		CD4AC5281496AE2F0087C4EF /* Composite.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; name = Composite.wav; path = platform/audio/resources/Composite.wav; sourceTree = SOURCE_ROOT; };
-		CD4BE5291CE13425009D87DA /* GenericTaskQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GenericTaskQueue.cpp; sourceTree = "<group>"; };
 		CD4E0AFA11F7BC27009D3811 /* fullscreen.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = fullscreen.css; sourceTree = "<group>"; };
 		CD4E4E602357B317007895C3 /* HdrMetadataType.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = HdrMetadataType.idl; sourceTree = "<group>"; };
 		CD4E4E622357B3AD007895C3 /* TransferFunction.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = TransferFunction.idl; sourceTree = "<group>"; };
@@ -28067,7 +28066,6 @@
 				BC073BA90C399B1F000F5979 /* FloatConversion.h */,
 				4190F3A1249D152700531C57 /* FrameRateMonitor.cpp */,
 				4190F3A3249D152800531C57 /* FrameRateMonitor.h */,
-				CD4BE5291CE13425009D87DA /* GenericTaskQueue.cpp */,
 				CD62FB941AF018E70012ED7D /* GenericTaskQueue.h */,
 				A8748BDF12CBF2DC001FBA41 /* HashTools.h */,
 				BC3BC29B0E91AB0F00835588 /* HostWindow.h */,
@@ -32564,7 +32562,6 @@
 				63F5D4F70E8C4B7100C0BD04 /* ElementRareData.h in Headers */,
 				FBDB619F16D6036500BB3394 /* ElementRuleCollector.h in Headers */,
 				E4D58EBB17B8F12800CBDCA8 /* ElementTraversal.h in Headers */,
-				A8CFF6BE0A156118000A4234 /* LegacyEllipsisBox.h in Headers */,
 				F55B3DBC1251F12D003EF269 /* EmailInputType.h in Headers */,
 				B25599A50D00D8BA00BB825C /* EmptyClients.h in Headers */,
 				414DEDE71F9FE91E0047C40D /* EmptyFrameLoaderClient.h in Headers */,
@@ -33139,7 +33136,6 @@
 				CD063F831E23FA8900812BE3 /* InitDataRegistry.h in Headers */,
 				E30592641E27A3AD00D57C98 /* InlineClassicScript.h in Headers */,
 				6FE198172178397C00446F08 /* InlineContentBreaker.h in Headers */,
-				B57CB52E182A3EFC0079A647 /* LegacyInlineElementBox.h in Headers */,
 				6F7CA3CA208C2B2E002F29AB /* InlineFormattingContext.h in Headers */,
 				47C4D57D26508BCB00C7AB1F /* InlineFormattingGeometry.h in Headers */,
 				6FE636E82647962900F0951E /* InlineFormattingQuirks.h in Headers */,
@@ -33156,7 +33152,6 @@
 				E4D33F3B252AEECD00837D05 /* InlineRunAndOffset.h in Headers */,
 				6F360E5023999421001512A7 /* InlineSoftLineBreakItem.h in Headers */,
 				AA4C3A770B2B1679002334A2 /* InlineStyleSheetOwner.h in Headers */,
-				BCEA485A097D93020094C9E4 /* LegacyInlineTextBox.h in Headers */,
 				1C010701192594DF008A4201 /* InlineTextBoxStyle.h in Headers */,
 				6F1CC1DE225F8B4900720AD2 /* InlineTextItem.h in Headers */,
 				1CE8864126105BF2000C816C /* InMemoryDisplayList.h in Headers */,
@@ -34161,8 +34156,11 @@
 				CDF4B7121E0087AE00E235A2 /* LegacyCDMSession.h in Headers */,
 				CDE8B5F11A69778B00B4B66A /* LegacyCDMSessionClearKey.h in Headers */,
 				2DE70023192FE82A00B0975C /* LegacyDisplayRefreshMonitorMac.h in Headers */,
+				A8CFF6BE0A156118000A4234 /* LegacyEllipsisBox.h in Headers */,
 				A8CFF5E50A155A05000A4234 /* LegacyInlineBox.h in Headers */,
+				B57CB52E182A3EFC0079A647 /* LegacyInlineElementBox.h in Headers */,
 				A8CFF5E30A155A05000A4234 /* LegacyInlineFlowBox.h in Headers */,
+				BCEA485A097D93020094C9E4 /* LegacyInlineTextBox.h in Headers */,
 				E4E94D6122FF158A00DD191F /* LegacyLineLayout.h in Headers */,
 				F44A5F591FED38F2007F5944 /* LegacyNSPasteboardTypes.h in Headers */,
 				A185B42A1E8211A100DC9118 /* LegacyPreviewLoader.h in Headers */,

Modified: trunk/Source/WebCore/platform/DeferrableTask.h (278543 => 278544)


--- trunk/Source/WebCore/platform/DeferrableTask.h	2021-06-07 04:22:38 UTC (rev 278543)
+++ trunk/Source/WebCore/platform/DeferrableTask.h	2021-06-07 06:16:22 UTC (rev 278544)
@@ -25,7 +25,9 @@
 
 #pragma once
 
-#include "GenericTaskQueue.h"
+#include <wtf/Function.h>
+#include <wtf/MainThread.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
@@ -55,7 +57,7 @@
         cancelTask();
 
         m_isPending = true;
-        m_dispatcher.postTask([weakThis = makeWeakPtr(*this), task = WTFMove(task)] {
+        callOnMainThread([weakThis = makeWeakPtr(*this), task = WTFMove(task)] {
             if (!weakThis)
                 return;
             ASSERT(weakThis->isPending());
@@ -65,7 +67,6 @@
     }
 
 private:
-    MainThreadTaskDispatcher m_dispatcher;
     bool m_isPending { false };
     bool m_isClosed { false };
 };

Deleted: trunk/Source/WebCore/platform/GenericTaskQueue.cpp (278543 => 278544)


--- trunk/Source/WebCore/platform/GenericTaskQueue.cpp	2021-06-07 04:22:38 UTC (rev 278543)
+++ trunk/Source/WebCore/platform/GenericTaskQueue.cpp	2021-06-07 06:16:22 UTC (rev 278544)
@@ -1,100 +0,0 @@
-/*
- * 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.
- */
-
-#include "config.h"
-#include "GenericTaskQueue.h"
-
-#include <wtf/Lock.h>
-#include <wtf/MainThread.h>
-#include <wtf/NeverDestroyed.h>
-
-namespace WebCore {
-
-Lock MainThreadTaskDispatcher::s_sharedLock;
-
-MainThreadTaskDispatcher::MainThreadTaskDispatcher()
-{
-}
-
-void MainThreadTaskDispatcher::postTask(Function<void()>&& function)
-{
-    {
-        Locker locker { s_sharedLock };
-        m_pendingTasks.append(WTFMove(function));
-        pendingDispatchers().append(makeWeakPtr(*this));
-    }
-
-    ensureOnMainThread([] {
-        if (!sharedTimer().isActive())
-            sharedTimer().startOneShot(0_s);
-    });
-}
-
-Timer& MainThreadTaskDispatcher::sharedTimer()
-{
-    ASSERT(isMainThread());
-    static NeverDestroyed<Timer> timer([] { MainThreadTaskDispatcher::sharedTimerFired(); });
-    return timer.get();
-}
-
-void MainThreadTaskDispatcher::sharedTimerFired()
-{
-    ASSERT(!sharedTimer().isActive());
-
-    // Copy the pending events first because we don't want to process synchronously the new events
-    // queued by the JS events handlers that are executed in the loop below.
-    Deque<WeakPtr<MainThreadTaskDispatcher>> queuedDispatchers;
-    {
-        Locker locker { s_sharedLock };
-        queuedDispatchers = std::exchange(pendingDispatchers(), { });
-    }
-    while (!queuedDispatchers.isEmpty()) {
-        WeakPtr<MainThreadTaskDispatcher> dispatcher = queuedDispatchers.takeFirst();
-        if (!dispatcher)
-            continue;
-        dispatcher->dispatchOneTask();
-    }
-}
-
-
-Deque<WeakPtr<MainThreadTaskDispatcher>>& MainThreadTaskDispatcher::pendingDispatchers()
-{
-    static NeverDestroyed<Deque<WeakPtr<MainThreadTaskDispatcher>>> dispatchers;
-    return dispatchers.get();
-}
-
-void MainThreadTaskDispatcher::dispatchOneTask()
-{
-    Function<void()> task;
-    {
-        Locker locker { s_sharedLock };
-        ASSERT(!m_pendingTasks.isEmpty());
-        task = m_pendingTasks.takeFirst();
-    }
-    task();
-}
-
-}
-

Modified: trunk/Source/WebCore/platform/GenericTaskQueue.h (278543 => 278544)


--- trunk/Source/WebCore/platform/GenericTaskQueue.h	2021-06-07 04:22:38 UTC (rev 278543)
+++ trunk/Source/WebCore/platform/GenericTaskQueue.h	2021-06-07 06:16:22 UTC (rev 278544)
@@ -28,36 +28,12 @@
 #include "ContextDestructionObserver.h"
 #include "EventLoop.h"
 #include "ScriptExecutionContext.h"
-#include "Timer.h"
-#include <wtf/Deque.h>
 #include <wtf/Function.h>
 #include <wtf/MainThread.h>
-#include <wtf/UniqueRef.h>
 #include <wtf/WeakPtr.h>
 
-namespace WTF {
-class Lock;
-}
-
 namespace WebCore {
 
-class MainThreadTaskDispatcher : public CanMakeWeakPtr<MainThreadTaskDispatcher, WeakPtrFactoryInitialization::Eager> {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    MainThreadTaskDispatcher();
-    void postTask(Function<void()>&&);
-
-private:
-    static Timer& sharedTimer();
-    static void sharedTimerFired();
-    static Deque<WeakPtr<MainThreadTaskDispatcher>>& pendingDispatchers() WTF_REQUIRES_LOCK(s_sharedLock);
-
-    void dispatchOneTask();
-
-    static Lock s_sharedLock;
-    Deque<Function<void()>> m_pendingTasks WTF_GUARDED_BY_LOCK(s_sharedLock);
-};
-
 class TaskQueueBase : public CanMakeWeakPtr<TaskQueueBase> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
@@ -91,17 +67,10 @@
 class MainThreadTaskQueue : public TaskQueueBase {
 public:
     MainThreadTaskQueue()
-        : m_dispatcher(makeUniqueRef<MainThreadTaskDispatcher>())
     {
         ASSERT(isMainThread());
     }
 
-    ~MainThreadTaskQueue()
-    {
-        if (!isMainThread())
-            m_dispatcher->postTask([dispatcher = WTFMove(m_dispatcher)] { });
-    }
-
     void enqueueTask(Function<void()>&& task)
     {
         if (isClosed())
@@ -108,7 +77,7 @@
             return;
 
         incrementPendingTasks();
-        m_dispatcher->postTask([weakThis = makeWeakPtr(*this), task = WTFMove(task)] {
+        callOnMainThread([weakThis = makeWeakPtr(*this), task = WTFMove(task)] {
             if (!weakThis)
                 return;
             weakThis->decrementPendingTasks();
@@ -115,9 +84,6 @@
             task();
         });
     }
-
-private:
-    UniqueRef<MainThreadTaskDispatcher> m_dispatcher;
 };
 
 // Similar to MainThreadTaskQueue but based on the HTML event loop.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to