Title: [263524] trunk/Source/WTF
- Revision
- 263524
- Author
- tzaga...@apple.com
- Date
- 2020-06-25 12:38:13 -0700 (Thu, 25 Jun 2020)
Log Message
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):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (263523 => 263524)
--- trunk/Source/WTF/ChangeLog 2020-06-25 19:32:34 UTC (rev 263523)
+++ trunk/Source/WTF/ChangeLog 2020-06-25 19:38:13 UTC (rev 263524)
@@ -1,3 +1,24 @@
+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-24 Umar Iqbal <uiq...@apple.com>
We should resurrect the older patch that collects some statistics of web API calls
Modified: trunk/Source/WTF/wtf/RunLoop.cpp (263523 => 263524)
--- trunk/Source/WTF/wtf/RunLoop.cpp 2020-06-25 19:32:34 UTC (rev 263523)
+++ trunk/Source/WTF/wtf/RunLoop.cpp 2020-06-25 19:38:13 UTC (rev 263524)
@@ -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: trunk/Source/WTF/wtf/RunLoop.h (263523 => 263524)
--- trunk/Source/WTF/wtf/RunLoop.h 2020-06-25 19:32:34 UTC (rev 263523)
+++ trunk/Source/WTF/wtf/RunLoop.h 2020-06-25 19:38:13 UTC (rev 263524)
@@ -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: trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm (263523 => 263524)
--- trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm 2020-06-25 19:32:34 UTC (rev 263523)
+++ trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm 2020-06-25 19:38:13 UTC (rev 263524)
@@ -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 {
@@ -54,6 +67,8 @@
WTFLogChannel LogThreading = { WTFLogChannelState::On, "Threading", WTFLogLevel::Error, LOG_CHANNEL_WEBKIT_SUBSYSTEM, OS_LOG_DEFAULT };
#endif
+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;
@@ -67,6 +82,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];
}
void scheduleDispatchFunctionsOnMainThread()
@@ -78,7 +96,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