Title: [262863] trunk/Source/WTF
Revision
262863
Author
[email protected]
Date
2020-06-10 15:03:12 -0700 (Wed, 10 Jun 2020)

Log Message

[Cocoa] Build callOnMainThread on WTF::RunLoop rather than on NSObject methods
https://bugs.webkit.org/show_bug.cgi?id=213043

Reviewed by Simon Fraser.

Original patch by Sihui Liu.

>From https://bugs.webkit.org/show_bug.cgi?id=202874, this is the subset
of Sihui's patch that unifies some of RunLoop and callOnMainThread.

My goal is to simplify the code, and shrink the diff when testing
CFRunLoopSource1 in the future.

* wtf/RunLoop.cpp:
(WTF::RunLoop::initializeWebRunLoop):
(WTF::RunLoop::web):
* wtf/RunLoop.h:
* wtf/cocoa/MainThreadCocoa.mm:
(WTF::initializeMainThreadPlatform):
(WTF::scheduleDispatchFunctionsOnMainThread):
(WTF::initializeWebThread):
(-[JSWTFMainThreadCaller call]): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (262862 => 262863)


--- trunk/Source/WTF/ChangeLog	2020-06-10 21:47:23 UTC (rev 262862)
+++ trunk/Source/WTF/ChangeLog	2020-06-10 22:03:12 UTC (rev 262863)
@@ -1,3 +1,28 @@
+2020-06-10  Geoffrey Garen  <[email protected]>
+
+        [Cocoa] Build callOnMainThread on WTF::RunLoop rather than on NSObject methods
+        https://bugs.webkit.org/show_bug.cgi?id=213043
+
+        Reviewed by Simon Fraser.
+
+        Original patch by Sihui Liu.
+
+        From https://bugs.webkit.org/show_bug.cgi?id=202874, this is the subset
+        of Sihui's patch that unifies some of RunLoop and callOnMainThread.
+
+        My goal is to simplify the code, and shrink the diff when testing
+        CFRunLoopSource1 in the future.
+
+        * wtf/RunLoop.cpp:
+        (WTF::RunLoop::initializeWebRunLoop):
+        (WTF::RunLoop::web):
+        * wtf/RunLoop.h:
+        * wtf/cocoa/MainThreadCocoa.mm:
+        (WTF::initializeMainThreadPlatform):
+        (WTF::scheduleDispatchFunctionsOnMainThread):
+        (WTF::initializeWebThread):
+        (-[JSWTFMainThreadCaller call]): Deleted.
+
 2020-06-10  Jer Noble  <[email protected]>
 
         Catalyst WebKit apps continue to play audio after quitting

Modified: trunk/Source/WTF/wtf/RunLoop.cpp (262862 => 262863)


--- trunk/Source/WTF/wtf/RunLoop.cpp	2020-06-10 21:47:23 UTC (rev 262862)
+++ trunk/Source/WTF/wtf/RunLoop.cpp	2020-06-10 22:03:12 UTC (rev 262863)
@@ -33,6 +33,9 @@
 namespace WTF {
 
 static RunLoop* s_mainRunLoop;
+#if USE(WEB_THREAD)
+static RunLoop* s_webRunLoop;
+#endif
 
 // Helper class for ThreadSpecificData.
 class RunLoop::Holder {
@@ -69,6 +72,19 @@
     return *s_mainRunLoop;
 }
 
+#if USE(WEB_THREAD)
+void RunLoop::initializeWebRunLoop()
+{
+    s_webRunLoop = &RunLoop::current();
+}
+
+RunLoop& RunLoop::web()
+{
+    ASSERT(s_webRunLoop);
+    return *s_webRunLoop;
+}
+#endif
+
 bool RunLoop::isMain()
 {
     ASSERT(s_mainRunLoop);

Modified: trunk/Source/WTF/wtf/RunLoop.h (262862 => 262863)


--- trunk/Source/WTF/wtf/RunLoop.h	2020-06-10 21:47:23 UTC (rev 262862)
+++ trunk/Source/WTF/wtf/RunLoop.h	2020-06-10 22:03:12 UTC (rev 262863)
@@ -61,9 +61,15 @@
     // Must be called from the main thread (except for the Mac platform, where it
     // can be called from any thread).
     WTF_EXPORT_PRIVATE static void initializeMainRunLoop();
+#if USE(WEB_THREAD)
+    WTF_EXPORT_PRIVATE static void initializeWebRunLoop();
+#endif
 
     WTF_EXPORT_PRIVATE static RunLoop& current();
     WTF_EXPORT_PRIVATE static RunLoop& main();
+#if USE(WEB_THREAD)
+    WTF_EXPORT_PRIVATE static RunLoop& web();
+#endif
     WTF_EXPORT_PRIVATE static bool isMain();
     ~RunLoop() final;
 

Modified: trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm (262862 => 262863)


--- trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm	2020-06-10 21:47:23 UTC (rev 262862)
+++ trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm	2020-06-10 22:03:12 UTC (rev 262863)
@@ -36,6 +36,7 @@
 #import <wtf/Assertions.h>
 #import <wtf/HashSet.h>
 #import <wtf/RetainPtr.h>
+#import <wtf/RunLoop.h>
 #import <wtf/SchedulePair.h>
 #import <wtf/Threading.h>
 
@@ -43,19 +44,6 @@
 #import <wtf/ios/WebCoreThread.h>
 #endif
 
-@interface JSWTFMainThreadCaller : NSObject
-- (void)call;
-@end
-
-@implementation JSWTFMainThreadCaller
-
-- (void)call
-{
-    WTF::dispatchFunctionsFromMainThread();
-}
-
-@end
-
 #define LOG_CHANNEL_PREFIX Log
 
 namespace WTF {
@@ -66,8 +54,6 @@
 WTFLogChannel LogThreading = { WTFLogChannelState::On, "Threading", WTFLogLevel::Error, LOG_CHANNEL_WEBKIT_SUBSYSTEM, OS_LOG_DEFAULT };
 #endif
 
-
-static JSWTFMainThreadCaller* staticMainThreadCaller;
 static bool isTimerPosted; // This is only accessed on the main thread.
 
 #if USE(WEB_THREAD)
@@ -84,9 +70,6 @@
     if (!pthread_main_np())
         RELEASE_LOG_FAULT(Threading, "WebKit Threading Violation - initial use of WebKit from a secondary thread.");
     ASSERT(pthread_main_np());
-
-    ASSERT(!staticMainThreadCaller);
-    staticMainThreadCaller = [[JSWTFMainThreadCaller alloc] init];
 }
 
 static void timerFired(CFRunLoopTimerRef timer, void*)
@@ -112,8 +95,6 @@
 
 void scheduleDispatchFunctionsOnMainThread()
 {
-    ASSERT(staticMainThreadCaller);
-    
 #if USE(WEB_THREAD)
     if (isWebThread()) {
         postTimer();
@@ -121,7 +102,7 @@
     }
 
     if (mainThreadPthread) {
-        [staticMainThreadCaller performSelector:@selector(call) onThread:mainThreadNSThread withObject:nil waitUntilDone:NO];
+        RunLoop::web().dispatch(dispatchFunctionsFromMainThread);
         return;
     }
 #else
@@ -131,7 +112,7 @@
     }
 #endif
 
-    [staticMainThreadCaller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:NO];
+    RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
 }
 
 void dispatchAsyncOnMainThreadWithWebThreadLockIfNeeded(void (^block)())
@@ -196,6 +177,7 @@
         mainThreadPthread = pthread_self();
         mainThreadNSThread = [NSThread currentThread];
         sWebThread = &Thread::current();
+        RunLoop::initializeWebRunLoop();
     });
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to