- Revision
- 212878
- Author
- [email protected]
- Date
- 2017-02-22 23:10:54 -0800 (Wed, 22 Feb 2017)
Log Message
Better handle Thread and RunLoop initialization
https://bugs.webkit.org/show_bug.cgi?id=167828
Reviewed by Yusuke Suzuki.
Source/_javascript_Core:
* runtime/InitializeThreading.cpp:
(JSC::initializeThreading): Do not initialize double_conversion, that is already initialized by WTF, and GC
threads that will be initialized by WTF main thread when needed.
Source/WebKit/win:
Remove unnecessary call to WTF::initializeMainThread().
* WebView.cpp:
(WebView::WebView):
Source/WebKit2:
Remove unnecessary call to WTF::initializeMainThread().
* Shared/WebKit2Initialize.cpp:
(WebKit::InitializeWebKit2):
Source/WTF:
Make initialization functions more independent so that they can run in different
order. WTF::initializeMainThread initializes WTF threading, so that neither WTF nor JSC theading need to be
initialized before. RunLoop::initializeMainRunLoop() requires main thread to be initialized in some
ports, so it initializes main thread too. WebKit1 always calls WTF::initializeMainThreadToProcessMainThread()
before RunLoop::initializeMainRunLoop() so there's no problem there. GC threads are initialized alwayas by the
main thread. The rules should be simpler now:
- JSC::initializeThreading: should always be called when JSC is used.
- WTF::initializeThreading: only needs to be explicitly called when JSC is not used and process doesn't
initialize a main thread or main run loop.
- WTF::initializeMainThread: only needs to be explicitly called if process initializes a main thread but not a
main run loop.
- WTF::initializeMainThreadToProcessMainThread(): should always be called in WebKit1 before
RunLoop::initializeMainRunLoop().
- RunLoop::initializeMainRunLoop(): to initialize the main run loop. The only requirement is JSC::initializeThreading()
to be called before if JSC is used.
* wtf/MainThread.cpp:
(WTF::initializeMainThreadOnce): Use pthread_once to initialize the main thread also in GTK+ port.
(WTF::initializeMainThreadToProcessMainThreadOnce): Call initializeThreading() before the platform
initialization and initializeGCThreads() after it.
(WTF::initializeMainThread): Ditto.
* wtf/RunLoop.cpp:
(WTF::RunLoop::initializeMainRunLoop): Call initializeMainThread().
* wtf/glib/MainThreadGLib.cpp:
(WTF::initializeMainThreadPlatform):
(WTF::isMainThread):
* wtf/mac/MainThreadMac.mm:
(WTF::initializeMainThreadPlatform): Remove call to initializeGCThreads().
(WTF::initializeMainThreadToProcessMainThreadPlatform): Ditto.
Tools:
Remove unnecessary calls to WTF::initializeMainThread().
* TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp:
(TestWebKitAPI::ComplexTextControllerTest::SetUp):
* TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
(TestWebKitAPI::ContentExtensionTest::SetUp):
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::initialize):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (212877 => 212878)
--- trunk/Source/_javascript_Core/ChangeLog 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Source/_javascript_Core/ChangeLog 2017-02-23 07:10:54 UTC (rev 212878)
@@ -1,3 +1,14 @@
+2017-02-22 Carlos Garcia Campos <[email protected]>
+
+ Better handle Thread and RunLoop initialization
+ https://bugs.webkit.org/show_bug.cgi?id=167828
+
+ Reviewed by Yusuke Suzuki.
+
+ * runtime/InitializeThreading.cpp:
+ (JSC::initializeThreading): Do not initialize double_conversion, that is already initialized by WTF, and GC
+ threads that will be initialized by WTF main thread when needed.
+
2017-02-22 JF Bastien <[email protected]>
WebAssembly: clear out insignificant i32 bits when calling _javascript_
Modified: trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp (212877 => 212878)
--- trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp 2017-02-23 07:10:54 UTC (rev 212878)
@@ -55,9 +55,7 @@
static std::once_flag initializeThreadingOnceFlag;
std::call_once(initializeThreadingOnceFlag, []{
- WTF::double_conversion::initialize();
WTF::initializeThreading();
- WTF::initializeGCThreads();
Options::initialize();
#if ENABLE(WRITE_BARRIER_PROFILING)
WriteBarrierCounters::initialize();
Modified: trunk/Source/WTF/ChangeLog (212877 => 212878)
--- trunk/Source/WTF/ChangeLog 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Source/WTF/ChangeLog 2017-02-23 07:10:54 UTC (rev 212878)
@@ -1,3 +1,41 @@
+2017-02-22 Carlos Garcia Campos <[email protected]>
+
+ Better handle Thread and RunLoop initialization
+ https://bugs.webkit.org/show_bug.cgi?id=167828
+
+ Reviewed by Yusuke Suzuki.
+
+ Make initialization functions more independent so that they can run in different
+ order. WTF::initializeMainThread initializes WTF threading, so that neither WTF nor JSC theading need to be
+ initialized before. RunLoop::initializeMainRunLoop() requires main thread to be initialized in some
+ ports, so it initializes main thread too. WebKit1 always calls WTF::initializeMainThreadToProcessMainThread()
+ before RunLoop::initializeMainRunLoop() so there's no problem there. GC threads are initialized alwayas by the
+ main thread. The rules should be simpler now:
+
+ - JSC::initializeThreading: should always be called when JSC is used.
+ - WTF::initializeThreading: only needs to be explicitly called when JSC is not used and process doesn't
+ initialize a main thread or main run loop.
+ - WTF::initializeMainThread: only needs to be explicitly called if process initializes a main thread but not a
+ main run loop.
+ - WTF::initializeMainThreadToProcessMainThread(): should always be called in WebKit1 before
+ RunLoop::initializeMainRunLoop().
+ - RunLoop::initializeMainRunLoop(): to initialize the main run loop. The only requirement is JSC::initializeThreading()
+ to be called before if JSC is used.
+
+ * wtf/MainThread.cpp:
+ (WTF::initializeMainThreadOnce): Use pthread_once to initialize the main thread also in GTK+ port.
+ (WTF::initializeMainThreadToProcessMainThreadOnce): Call initializeThreading() before the platform
+ initialization and initializeGCThreads() after it.
+ (WTF::initializeMainThread): Ditto.
+ * wtf/RunLoop.cpp:
+ (WTF::RunLoop::initializeMainRunLoop): Call initializeMainThread().
+ * wtf/glib/MainThreadGLib.cpp:
+ (WTF::initializeMainThreadPlatform):
+ (WTF::isMainThread):
+ * wtf/mac/MainThreadMac.mm:
+ (WTF::initializeMainThreadPlatform): Remove call to initializeGCThreads().
+ (WTF::initializeMainThreadToProcessMainThreadPlatform): Ditto.
+
2017-02-22 Myles C. Maxfield <[email protected]>
[Cocoa] Remove Yosemite-specific font lookup code
Modified: trunk/Source/WTF/wtf/MainThread.cpp (212877 => 212878)
--- trunk/Source/WTF/wtf/MainThread.cpp 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Source/WTF/wtf/MainThread.cpp 2017-02-23 07:10:54 UTC (rev 212878)
@@ -41,7 +41,7 @@
namespace WTF {
static bool callbacksPaused; // This global variable is only accessed from main thread.
-#if !OS(DARWIN) || PLATFORM(GTK)
+#if !OS(DARWIN) && !PLATFORM(GTK)
static ThreadIdentifier mainThreadIdentifier;
#endif
@@ -53,28 +53,14 @@
return functionQueue;
}
-#if !OS(DARWIN) || PLATFORM(GTK)
-
-void initializeMainThread()
-{
- static bool initializedMainThread;
- if (initializedMainThread)
- return;
- initializedMainThread = true;
-
- mainThreadIdentifier = currentThread();
-
- initializeMainThreadPlatform();
- initializeGCThreads();
-}
-
-#else
-
+#if OS(DARWIN) || PLATFORM(GTK)
static pthread_once_t initializeMainThreadKeyOnce = PTHREAD_ONCE_INIT;
static void initializeMainThreadOnce()
{
+ initializeThreading();
initializeMainThreadPlatform();
+ initializeGCThreads();
}
void initializeMainThread()
@@ -82,10 +68,12 @@
pthread_once(&initializeMainThreadKeyOnce, initializeMainThreadOnce);
}
-#if !USE(WEB_THREAD)
+#if !USE(WEB_THREAD) && !PLATFORM(GTK)
static void initializeMainThreadToProcessMainThreadOnce()
{
+ initializeThreading();
initializeMainThreadToProcessMainThreadPlatform();
+ initializeGCThreads();
}
void initializeMainThreadToProcessMainThread()
@@ -92,7 +80,7 @@
{
pthread_once(&initializeMainThreadKeyOnce, initializeMainThreadToProcessMainThreadOnce);
}
-#else
+#elif !PLATFORM(GTK)
static pthread_once_t initializeWebThreadKeyOnce = PTHREAD_ONCE_INIT;
static void initializeWebThreadOnce()
@@ -106,6 +94,20 @@
}
#endif // !USE(WEB_THREAD)
+#else
+void initializeMainThread()
+{
+ static bool initializedMainThread;
+ if (initializedMainThread)
+ return;
+ initializedMainThread = true;
+
+ initializeThreading();
+ mainThreadIdentifier = currentThread();
+
+ initializeMainThreadPlatform();
+ initializeGCThreads();
+}
#endif
// 0.1 sec delays in UI is approximate threshold when they become noticeable. Have a limit that's half of that.
@@ -176,7 +178,7 @@
scheduleDispatchFunctionsOnMainThread();
}
-#if !OS(DARWIN) || PLATFORM(GTK)
+#if !OS(DARWIN) && !PLATFORM(GTK)
bool isMainThread()
{
return currentThread() == mainThreadIdentifier;
Modified: trunk/Source/WTF/wtf/RunLoop.cpp (212877 => 212878)
--- trunk/Source/WTF/wtf/RunLoop.cpp 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Source/WTF/wtf/RunLoop.cpp 2017-02-23 07:10:54 UTC (rev 212878)
@@ -52,6 +52,7 @@
{
if (s_mainRunLoop)
return;
+ initializeMainThread();
s_mainRunLoop = &RunLoop::current();
}
Modified: trunk/Source/WTF/wtf/glib/MainThreadGLib.cpp (212877 => 212878)
--- trunk/Source/WTF/wtf/glib/MainThreadGLib.cpp 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Source/WTF/wtf/glib/MainThreadGLib.cpp 2017-02-23 07:10:54 UTC (rev 212878)
@@ -33,6 +33,8 @@
#include <glib.h>
#include <wtf/RunLoop.h>
+static pthread_t mainThreadPthread;
+
namespace WTF {
class MainThreadDispatcher {
@@ -59,8 +61,15 @@
void initializeMainThreadPlatform()
{
+ mainThreadPthread = pthread_self();
}
+bool isMainThread()
+{
+ ASSERT(mainThreadPthread);
+ return pthread_equal(pthread_self(), mainThreadPthread);
+}
+
void scheduleDispatchFunctionsOnMainThread()
{
// Use a RunLoop::Timer instead of RunLoop::dispatch() to be able to use a different priority and
Modified: trunk/Source/WTF/wtf/mac/MainThreadMac.mm (212877 => 212878)
--- trunk/Source/WTF/wtf/mac/MainThreadMac.mm 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Source/WTF/wtf/mac/MainThreadMac.mm 2017-02-23 07:10:54 UTC (rev 212878)
@@ -82,8 +82,6 @@
ASSERT(!mainThreadPthread);
ASSERT(!mainThreadNSThread);
#endif
-
- initializeGCThreads();
}
#if !USE(WEB_THREAD)
@@ -98,8 +96,6 @@
mainThreadEstablishedAsPthreadMain = true;
mainThreadPthread = 0;
mainThreadNSThread = nil;
-
- initializeGCThreads();
}
#endif // !USE(WEB_THREAD)
Modified: trunk/Source/WebKit/win/ChangeLog (212877 => 212878)
--- trunk/Source/WebKit/win/ChangeLog 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Source/WebKit/win/ChangeLog 2017-02-23 07:10:54 UTC (rev 212878)
@@ -1,3 +1,15 @@
+2017-02-22 Carlos Garcia Campos <[email protected]>
+
+ Better handle Thread and RunLoop initialization
+ https://bugs.webkit.org/show_bug.cgi?id=167828
+
+ Reviewed by Yusuke Suzuki.
+
+ Remove unnecessary call to WTF::initializeMainThread().
+
+ * WebView.cpp:
+ (WebView::WebView):
+
2017-02-20 Per Arne Vollan <[email protected]>
[Win] Custom scale factor is not applied in all cases.
Modified: trunk/Source/WebKit/win/WebView.cpp (212877 => 212878)
--- trunk/Source/WebKit/win/WebView.cpp 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Source/WebKit/win/WebView.cpp 2017-02-23 07:10:54 UTC (rev 212878)
@@ -409,7 +409,6 @@
WebView::WebView()
{
JSC::initializeThreading();
- WTF::initializeMainThread();
RunLoop::initializeMainRunLoop();
m_backingStoreSize.cx = m_backingStoreSize.cy = 0;
Modified: trunk/Source/WebKit2/ChangeLog (212877 => 212878)
--- trunk/Source/WebKit2/ChangeLog 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Source/WebKit2/ChangeLog 2017-02-23 07:10:54 UTC (rev 212878)
@@ -1,3 +1,15 @@
+2017-02-22 Carlos Garcia Campos <[email protected]>
+
+ Better handle Thread and RunLoop initialization
+ https://bugs.webkit.org/show_bug.cgi?id=167828
+
+ Reviewed by Yusuke Suzuki.
+
+ Remove unnecessary call to WTF::initializeMainThread().
+
+ * Shared/WebKit2Initialize.cpp:
+ (WebKit::InitializeWebKit2):
+
2017-02-22 Chris Dumez <[email protected]>
Unreviewed, drop console logging landed by mistake as part of r212832.
Modified: trunk/Source/WebKit2/Shared/WebKit2Initialize.cpp (212877 => 212878)
--- trunk/Source/WebKit2/Shared/WebKit2Initialize.cpp 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Source/WebKit2/Shared/WebKit2Initialize.cpp 2017-02-23 07:10:54 UTC (rev 212878)
@@ -51,7 +51,6 @@
#endif
JSC::initializeThreading();
- WTF::initializeMainThread();
RunLoop::initializeMainRunLoop();
#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
Modified: trunk/Tools/ChangeLog (212877 => 212878)
--- trunk/Tools/ChangeLog 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Tools/ChangeLog 2017-02-23 07:10:54 UTC (rev 212878)
@@ -1,3 +1,19 @@
+2017-02-22 Carlos Garcia Campos <[email protected]>
+
+ Better handle Thread and RunLoop initialization
+ https://bugs.webkit.org/show_bug.cgi?id=167828
+
+ Reviewed by Yusuke Suzuki.
+
+ Remove unnecessary calls to WTF::initializeMainThread().
+
+ * TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp:
+ (TestWebKitAPI::ComplexTextControllerTest::SetUp):
+ * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp:
+ (TestWebKitAPI::ContentExtensionTest::SetUp):
+ * WebKitTestRunner/TestController.cpp:
+ (WTR::TestController::initialize):
+
2017-02-22 Myles C. Maxfield <[email protected]>
[Cocoa] Remove Yosemite-specific font lookup code
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp (212877 => 212878)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ComplexTextController.cpp 2017-02-23 07:10:54 UTC (rev 212878)
@@ -39,7 +39,6 @@
public:
virtual void SetUp()
{
- WTF::initializeMainThread();
JSC::initializeThreading();
RunLoop::initializeMainRunLoop();
}
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp (212877 => 212878)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp 2017-02-23 07:10:54 UTC (rev 212878)
@@ -76,7 +76,6 @@
public:
virtual void SetUp()
{
- WTF::initializeMainThread();
JSC::initializeThreading();
RunLoop::initializeMainRunLoop();
}
Modified: trunk/Tools/WebKitTestRunner/TestController.cpp (212877 => 212878)
--- trunk/Tools/WebKitTestRunner/TestController.cpp 2017-02-23 06:35:50 UTC (rev 212877)
+++ trunk/Tools/WebKitTestRunner/TestController.cpp 2017-02-23 07:10:54 UTC (rev 212878)
@@ -331,7 +331,6 @@
void TestController::initialize(int argc, const char* argv[])
{
JSC::initializeThreading();
- WTF::initializeMainThread();
RunLoop::initializeMainRunLoop();
platformInitialize();