Title: [263542] branches/safari-610.1.18-branch/Source/WTF
Revision
263542
Author
alanc...@apple.com
Date
2020-06-25 16:27:25 -0700 (Thu, 25 Jun 2020)

Log Message

Cherry-pick r263524. rdar://problem/64778728

    WTF::callOnMainThread should not require the main runloop to be initialized
    https://bugs.webkit.org/show_bug.cgi?id=213612
    <rdar://problem/64446028>

    Reviewed by Yusuke Suzuki.

    When using _javascript_Core as a framework, the WTF main runloop is never initialized. However,
    the inspector uses CFString wrappers, which use `callOnMainThread` when deallocating the
    underlying string. For now, we bring back the old `JSWTFMainThreadCaller` to ensure we have
    a way of dispatching to the main thread, even when the main runloop hasn't been initialized.

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

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@263524 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-610.1.18-branch/Source/WTF/ChangeLog (263541 => 263542)


--- branches/safari-610.1.18-branch/Source/WTF/ChangeLog	2020-06-25 23:27:21 UTC (rev 263541)
+++ branches/safari-610.1.18-branch/Source/WTF/ChangeLog	2020-06-25 23:27:25 UTC (rev 263542)
@@ -1,3 +1,49 @@
+2020-06-25  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r263524. rdar://problem/64778728
+
+    WTF::callOnMainThread should not require the main runloop to be initialized
+    https://bugs.webkit.org/show_bug.cgi?id=213612
+    <rdar://problem/64446028>
+    
+    Reviewed by Yusuke Suzuki.
+    
+    When using _javascript_Core as a framework, the WTF main runloop is never initialized. However,
+    the inspector uses CFString wrappers, which use `callOnMainThread` when deallocating the
+    underlying string. For now, we bring back the old `JSWTFMainThreadCaller` to ensure we have
+    a way of dispatching to the main thread, even when the main runloop hasn't been initialized.
+    
+    * wtf/RunLoop.cpp:
+    (WTF::RunLoop::mainIfExists):
+    * wtf/RunLoop.h:
+    * wtf/cocoa/MainThreadCocoa.mm:
+    (-[JSWTFMainThreadCaller call]):
+    (WTF::initializeMainThreadPlatform):
+    (WTF::scheduleDispatchFunctionsOnMainThread):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@263524 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-06-25  Tadeu Zagallo  <tzaga...@apple.com>
+
+            WTF::callOnMainThread should not require the main runloop to be initialized
+            https://bugs.webkit.org/show_bug.cgi?id=213612
+            <rdar://problem/64446028>
+
+            Reviewed by Yusuke Suzuki.
+
+            When using _javascript_Core as a framework, the WTF main runloop is never initialized. However,
+            the inspector uses CFString wrappers, which use `callOnMainThread` when deallocating the
+            underlying string. For now, we bring back the old `JSWTFMainThreadCaller` to ensure we have
+            a way of dispatching to the main thread, even when the main runloop hasn't been initialized.
+
+            * wtf/RunLoop.cpp:
+            (WTF::RunLoop::mainIfExists):
+            * wtf/RunLoop.h:
+            * wtf/cocoa/MainThreadCocoa.mm:
+            (-[JSWTFMainThreadCaller call]):
+            (WTF::initializeMainThreadPlatform):
+            (WTF::scheduleDispatchFunctionsOnMainThread):
+
 2020-06-21  Yusuke Suzuki  <ysuz...@apple.com>
 
         [WTF] Ensure ASCIILiteral is ASCII characters at compile time

Modified: branches/safari-610.1.18-branch/Source/WTF/wtf/RunLoop.cpp (263541 => 263542)


--- branches/safari-610.1.18-branch/Source/WTF/wtf/RunLoop.cpp	2020-06-25 23:27:21 UTC (rev 263541)
+++ branches/safari-610.1.18-branch/Source/WTF/wtf/RunLoop.cpp	2020-06-25 23:27:25 UTC (rev 263542)
@@ -57,6 +57,7 @@
     if (s_mainRunLoop)
         return;
     initializeMainThread();
+    WTF::storeStoreFence();
     s_mainRunLoop = &RunLoop::current();
 }
 
@@ -72,6 +73,11 @@
     return *s_mainRunLoop;
 }
 
+RunLoop* RunLoop::mainIfExists()
+{
+    return s_mainRunLoop;
+}
+
 #if USE(WEB_THREAD)
 void RunLoop::initializeWeb()
 {

Modified: branches/safari-610.1.18-branch/Source/WTF/wtf/RunLoop.h (263541 => 263542)


--- branches/safari-610.1.18-branch/Source/WTF/wtf/RunLoop.h	2020-06-25 23:27:21 UTC (rev 263541)
+++ branches/safari-610.1.18-branch/Source/WTF/wtf/RunLoop.h	2020-06-25 23:27:25 UTC (rev 263542)
@@ -67,6 +67,7 @@
 
     WTF_EXPORT_PRIVATE static RunLoop& current();
     WTF_EXPORT_PRIVATE static RunLoop& main();
+    WTF_EXPORT_PRIVATE static RunLoop* mainIfExists();
 #if USE(WEB_THREAD)
     WTF_EXPORT_PRIVATE static RunLoop& web();
     WTF_EXPORT_PRIVATE static RunLoop* webIfExists();

Modified: branches/safari-610.1.18-branch/Source/WTF/wtf/cocoa/MainThreadCocoa.mm (263541 => 263542)


--- branches/safari-610.1.18-branch/Source/WTF/wtf/cocoa/MainThreadCocoa.mm	2020-06-25 23:27:21 UTC (rev 263541)
+++ branches/safari-610.1.18-branch/Source/WTF/wtf/cocoa/MainThreadCocoa.mm	2020-06-25 23:27:25 UTC (rev 263542)
@@ -44,6 +44,19 @@
 #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 {
@@ -56,6 +69,8 @@
 
 static bool isTimerPosted; // This is only accessed on the main thread.
 
+static JSWTFMainThreadCaller* staticMainThreadCaller;
+
 #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;
@@ -69,6 +84,9 @@
     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*)
@@ -111,7 +129,12 @@
     }
 #endif
 
-    RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
+    if (RunLoop::mainIfExists()) {
+        RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
+        return;
+    }
+
+    [staticMainThreadCaller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:NO];
 }
 
 void dispatchAsyncOnMainThreadWithWebThreadLockIfNeeded(void (^block)())
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to