Title: [262904] trunk/Source/WTF
Revision
262904
Author
[email protected]
Date
2020-06-11 09:28:32 -0700 (Thu, 11 Jun 2020)

Log Message

[Cocoa] Build callOnMainThread on WTF::RunLoop rather than on a timer
https://bugs.webkit.org/show_bug.cgi?id=213063

Reviewed by Anders Carlsson.

Always use the RunLoop API for main thread tasks.

Previously, callOnMainThread sometimes scheduled a timer and sometimes
used the RunLoop. (Ironically, the timer behavior was added in r55816
with the intention to establish a single point of execution. Now, it has
the opposite effect.)

I picked the RunLoop API rather than the timer API because it moves us
closer to universally applying the RunLoop speedup in
https://bugs.webkit.org/show_bug.cgi?id=202874. Also, it avoids
allocating a timer, which can be expensive.

* wtf/cocoa/MainThreadCocoa.mm:
(WTF::scheduleDispatchFunctionsOnMainThread): The webIfExists() check
is a superset of the isWebThread() check, so we can just remove the
isWebThread() check when scheduling tasks to the web thread.
(WTF::timerFired): Deleted.
(WTF::postTimer): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (262903 => 262904)


--- trunk/Source/WTF/ChangeLog	2020-06-11 15:18:26 UTC (rev 262903)
+++ trunk/Source/WTF/ChangeLog	2020-06-11 16:28:32 UTC (rev 262904)
@@ -1,3 +1,29 @@
+2020-06-11  Geoffrey Garen  <[email protected]>
+
+        [Cocoa] Build callOnMainThread on WTF::RunLoop rather than on a timer
+        https://bugs.webkit.org/show_bug.cgi?id=213063
+
+        Reviewed by Anders Carlsson.
+
+        Always use the RunLoop API for main thread tasks.
+
+        Previously, callOnMainThread sometimes scheduled a timer and sometimes
+        used the RunLoop. (Ironically, the timer behavior was added in r55816
+        with the intention to establish a single point of execution. Now, it has
+        the opposite effect.)
+
+        I picked the RunLoop API rather than the timer API because it moves us
+        closer to universally applying the RunLoop speedup in
+        https://bugs.webkit.org/show_bug.cgi?id=202874. Also, it avoids
+        allocating a timer, which can be expensive.
+
+        * wtf/cocoa/MainThreadCocoa.mm:
+        (WTF::scheduleDispatchFunctionsOnMainThread): The webIfExists() check
+        is a superset of the isWebThread() check, so we can just remove the
+        isWebThread() check when scheduling tasks to the web thread.
+        (WTF::timerFired): Deleted.
+        (WTF::postTimer): Deleted.
+
 2020-06-10  Geoffrey Garen  <[email protected]>
 
         Some style improvements to main thread code

Modified: trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm (262903 => 262904)


--- trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm	2020-06-11 15:18:26 UTC (rev 262903)
+++ trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm	2020-06-11 16:28:32 UTC (rev 262904)
@@ -54,8 +54,6 @@
 WTFLogChannel LogThreading = { WTFLogChannelState::On, "Threading", WTFLogLevel::Error, LOG_CHANNEL_WEBKIT_SUBSYSTEM, OS_LOG_DEFAULT };
 #endif
 
-static bool isTimerPosted; // This is only accessed on the main thread.
-
 #if USE(WEB_THREAD)
 // When the Web thread is enabled, we consider it to be the main thread, not pthread main.
 static pthread_t s_webThreadPthread;
@@ -71,44 +69,13 @@
     ASSERT(pthread_main_np());
 }
 
-static void timerFired(CFRunLoopTimerRef timer, void*)
-{
-    CFRelease(timer);
-    isTimerPosted = false;
-
-    @autoreleasepool {
-        WTF::dispatchFunctionsFromMainThread();
-    }
-}
-
-static void postTimer()
-{
-    ASSERT(isMainThread());
-
-    if (isTimerPosted)
-        return;
-
-    isTimerPosted = true;
-    CFRunLoopAddTimer(CFRunLoopGetCurrent(), CFRunLoopTimerCreate(0, 0, 0, 0, 0, timerFired, 0), kCFRunLoopCommonModes);
-}
-
 void scheduleDispatchFunctionsOnMainThread()
 {
 #if USE(WEB_THREAD)
-    if (isWebThread()) {
-        postTimer();
-        return;
-    }
-
     if (auto* webRunLoop = RunLoop::webIfExists()) {
         webRunLoop->dispatch(dispatchFunctionsFromMainThread);
         return;
     }
-#else
-    if (isMainThread()) {
-        postTimer();
-        return;
-    }
 #endif
 
     RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to