Title: [263981] trunk/Source
Revision
263981
Author
[email protected]
Date
2020-07-06 12:51:49 -0700 (Mon, 06 Jul 2020)

Log Message

callOnMainThread should use the same queue as RunLoop::dispatch
https://bugs.webkit.org/show_bug.cgi?id=213830

Reviewed by Brady Eidson.

Source/_javascript_Core:

* _javascript_Core.order:

Source/WTF:

This should reduce flakiness in scheduled tasks.

There's no need to keep a separate queue anymore since both APIs have
the same semantics now.

* wtf/MainThread.cpp:
(WTF::callOnMainThread):
(WTF::functionQueue): Deleted.
(WTF::dispatchFunctionsFromMainThread): Deleted.
* wtf/MainThread.h:
* wtf/cocoa/MainThreadCocoa.mm:
(WTF::scheduleDispatchFunctionsOnMainThread): Deleted.
* wtf/generic/MainThreadGeneric.cpp:
(WTF::scheduleDispatchFunctionsOnMainThread): Deleted.
* wtf/win/MainThreadWin.cpp:
(WTF::scheduleDispatchFunctionsOnMainThread): Deleted.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (263980 => 263981)


--- trunk/Source/_javascript_Core/ChangeLog	2020-07-06 19:48:27 UTC (rev 263980)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-07-06 19:51:49 UTC (rev 263981)
@@ -1,3 +1,12 @@
+2020-07-06  Geoffrey Garen  <[email protected]>
+
+        callOnMainThread should use the same queue as RunLoop::dispatch
+        https://bugs.webkit.org/show_bug.cgi?id=213830
+
+        Reviewed by Brady Eidson.
+
+        * _javascript_Core.order:
+
 2020-07-05  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r263960.

Modified: trunk/Source/_javascript_Core/_javascript_Core.order (263980 => 263981)


--- trunk/Source/_javascript_Core/_javascript_Core.order	2020-07-06 19:48:27 UTC (rev 263980)
+++ trunk/Source/_javascript_Core/_javascript_Core.order	2020-07-06 19:51:49 UTC (rev 263981)
@@ -1020,7 +1020,6 @@
 __ZN3WTF7HashMapIPN3JSC6JSCellEjNS_7PtrHashIS3_EENS_10HashTraitsIS3_EENS6_IjEEE6removeENS_24HashTableIteratorAdapterINS_9HashTableIS3_NS_12KeyValuePairIS3_jEENS_24KeyValuePairKeyExtractorISD_EES5_NS_18HashMapValueTraitsIS7_S8_EES7_EESD_EE
 __ZN3WTF21PageAllocationAligned10deallocateEv
 -[JSWTFMainThreadCaller call]
-__ZN3WTF31dispatchFunctionsFromMainThreadEv
 __ZN3WTF7Unicode18convertUTF16ToUTF8EPPKtS2_PPcS4_b
 __ZN3WTF25TCMalloc_Central_FreeList11ShrinkCacheEib
 __ZN3WTF25TCMalloc_Central_FreeList18ReleaseListToSpansENS_11HardenedSLLE

Modified: trunk/Source/WTF/ChangeLog (263980 => 263981)


--- trunk/Source/WTF/ChangeLog	2020-07-06 19:48:27 UTC (rev 263980)
+++ trunk/Source/WTF/ChangeLog	2020-07-06 19:51:49 UTC (rev 263981)
@@ -1,3 +1,27 @@
+2020-07-06  Geoffrey Garen  <[email protected]>
+
+        callOnMainThread should use the same queue as RunLoop::dispatch
+        https://bugs.webkit.org/show_bug.cgi?id=213830
+
+        Reviewed by Brady Eidson.
+
+        This should reduce flakiness in scheduled tasks.
+
+        There's no need to keep a separate queue anymore since both APIs have
+        the same semantics now.
+
+        * wtf/MainThread.cpp:
+        (WTF::callOnMainThread):
+        (WTF::functionQueue): Deleted.
+        (WTF::dispatchFunctionsFromMainThread): Deleted.
+        * wtf/MainThread.h:
+        * wtf/cocoa/MainThreadCocoa.mm:
+        (WTF::scheduleDispatchFunctionsOnMainThread): Deleted.
+        * wtf/generic/MainThreadGeneric.cpp:
+        (WTF::scheduleDispatchFunctionsOnMainThread): Deleted.
+        * wtf/win/MainThreadWin.cpp:
+        (WTF::scheduleDispatchFunctionsOnMainThread): Deleted.
+
 2020-07-06  Michael Catanzaro  <[email protected]>
 
         Spams system logs with "Current memory footprint: 10 MB"

Modified: trunk/Source/WTF/wtf/MainThread.cpp (263980 => 263981)


--- trunk/Source/WTF/wtf/MainThread.cpp	2020-07-06 19:48:27 UTC (rev 263980)
+++ trunk/Source/WTF/wtf/MainThread.cpp	2020-07-06 19:51:49 UTC (rev 263981)
@@ -41,14 +41,6 @@
 
 namespace WTF {
 
-static Lock mainThreadFunctionQueueMutex;
-
-static Deque<Function<void ()>>& functionQueue()
-{
-    static NeverDestroyed<Deque<Function<void ()>>> functionQueue;
-    return functionQueue;
-}
-
 void initializeMainThread()
 {
     static std::once_flag initializeKey;
@@ -66,28 +58,6 @@
 }
 #endif
 
-void dispatchFunctionsFromMainThread()
-{
-    ASSERT(isMainThread());
-
-    Function<void ()> function;
-
-    while (true) {
-        {
-            auto locker = holdLock(mainThreadFunctionQueueMutex);
-            if (!functionQueue().size())
-                break;
-
-            function = functionQueue().takeFirst();
-        }
-
-        function();
-
-        // Clearing the function can have side effects, so do so outside of the lock above.
-        function = nullptr;
-    }
-}
-
 bool isMainRunLoop()
 {
     return RunLoop::isMain();
@@ -100,18 +70,14 @@
 
 void callOnMainThread(Function<void()>&& function)
 {
-    ASSERT(function);
-
-    bool needToSchedule = false;
-
-    {
-        auto locker = holdLock(mainThreadFunctionQueueMutex);
-        needToSchedule = functionQueue().size() == 0;
-        functionQueue().append(WTFMove(function));
+#if USE(WEB_THREAD)
+    if (auto* webRunLoop = RunLoop::webIfExists()) {
+        webRunLoop->dispatch(WTFMove(function));
+        return;
     }
+#endif
 
-    if (needToSchedule)
-        scheduleDispatchFunctionsOnMainThread();
+    RunLoop::main().dispatch(WTFMove(function));
 }
 
 bool isMainThreadOrGCThread()

Modified: trunk/Source/WTF/wtf/MainThread.h (263980 => 263981)


--- trunk/Source/WTF/wtf/MainThread.h	2020-07-06 19:48:27 UTC (rev 263980)
+++ trunk/Source/WTF/wtf/MainThread.h	2020-07-06 19:51:49 UTC (rev 263981)
@@ -72,8 +72,6 @@
 
 // NOTE: these functions are internal to the callOnMainThread implementation.
 void initializeMainThreadPlatform();
-void scheduleDispatchFunctionsOnMainThread();
-void dispatchFunctionsFromMainThread();
 
 } // namespace WTF
 

Modified: trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm (263980 => 263981)


--- trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm	2020-07-06 19:48:27 UTC (rev 263980)
+++ trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm	2020-07-06 19:51:49 UTC (rev 263981)
@@ -69,18 +69,6 @@
     ASSERT(pthread_main_np());
 }
 
-void scheduleDispatchFunctionsOnMainThread()
-{
-#if USE(WEB_THREAD)
-    if (auto* webRunLoop = RunLoop::webIfExists()) {
-        webRunLoop->dispatch(dispatchFunctionsFromMainThread);
-        return;
-    }
-#endif
-
-    RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
-}
-
 void dispatchAsyncOnMainThreadWithWebThreadLockIfNeeded(void (^block)())
 {
 #if USE(WEB_THREAD)

Modified: trunk/Source/WTF/wtf/generic/MainThreadGeneric.cpp (263980 => 263981)


--- trunk/Source/WTF/wtf/generic/MainThreadGeneric.cpp	2020-07-06 19:48:27 UTC (rev 263980)
+++ trunk/Source/WTF/wtf/generic/MainThreadGeneric.cpp	2020-07-06 19:51:49 UTC (rev 263981)
@@ -60,9 +60,4 @@
 #endif
 }
 
-void scheduleDispatchFunctionsOnMainThread()
-{
-    RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
-}
-
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/win/MainThreadWin.cpp (263980 => 263981)


--- trunk/Source/WTF/wtf/win/MainThreadWin.cpp	2020-07-06 19:48:27 UTC (rev 263980)
+++ trunk/Source/WTF/wtf/win/MainThreadWin.cpp	2020-07-06 19:51:49 UTC (rev 263981)
@@ -51,9 +51,4 @@
     return mainThread == Thread::currentID();
 }
 
-void scheduleDispatchFunctionsOnMainThread()
-{
-    RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
-}
-
 } // namespace WTF
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to