[GTK] [Win] Build callOnMainThread on WTF::RunLoop rather than on a timer
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Jun 2020 04:25:52 +0000 (04:25 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 30 Jun 2020 04:25:52 +0000 (04:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=213694

Reviewed by Carlos Garcia Campos.

As of https://bugs.webkit.org/show_bug.cgi?id=213063, Darwin platforms
use the RunLoop. Let's match them for consistency, and to delete some
code.

* wtf/generic/MainThreadGeneric.cpp:
(WTF::scheduleDispatchFunctionsOnMainThread):
(WTF::MainThreadDispatcher::MainThreadDispatcher): Deleted.
(WTF::MainThreadDispatcher::schedule): Deleted.
(WTF::MainThreadDispatcher::fired): Deleted.
* wtf/glib/RunLoopSourcePriority.h:
* wtf/win/MainThreadWin.cpp:
(WTF::initializeMainThreadPlatform):
(WTF::scheduleDispatchFunctionsOnMainThread):
(WTF::ThreadingWindowWndProc): Deleted.

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

Source/WTF/ChangeLog
Source/WTF/wtf/cf/RunLoopCF.cpp
Source/WTF/wtf/generic/MainThreadGeneric.cpp
Source/WTF/wtf/glib/RunLoopSourcePriority.h
Source/WTF/wtf/win/MainThreadWin.cpp

index 7af34a9..9c62ed0 100644 (file)
@@ -1,3 +1,25 @@
+2020-06-29  Geoffrey Garen  <ggaren@apple.com>
+
+        [GTK] [Win] Build callOnMainThread on WTF::RunLoop rather than on a timer
+        https://bugs.webkit.org/show_bug.cgi?id=213694
+
+        Reviewed by Carlos Garcia Campos.
+
+        As of https://bugs.webkit.org/show_bug.cgi?id=213063, Darwin platforms
+        use the RunLoop. Let's match them for consistency, and to delete some
+        code.
+
+        * wtf/generic/MainThreadGeneric.cpp:
+        (WTF::scheduleDispatchFunctionsOnMainThread):
+        (WTF::MainThreadDispatcher::MainThreadDispatcher): Deleted.
+        (WTF::MainThreadDispatcher::schedule): Deleted.
+        (WTF::MainThreadDispatcher::fired): Deleted.
+        * wtf/glib/RunLoopSourcePriority.h:
+        * wtf/win/MainThreadWin.cpp:
+        (WTF::initializeMainThreadPlatform):
+        (WTF::scheduleDispatchFunctionsOnMainThread):
+        (WTF::ThreadingWindowWndProc): Deleted.
+
 2020-06-29  Guowei Yang  <guowei_yang@apple.com>
 
         Adding Experimental Feature Flags for CoreImage backed SVG/CSS Filters
index a57f7a2..52eef75 100644 (file)
@@ -83,11 +83,15 @@ void RunLoop::stop()
 
 // RunLoop::Timer
 
-void RunLoop::TimerBase::timerFired(CFRunLoopTimerRef, void* context)
+void RunLoop::TimerBase::timerFired(CFRunLoopTimerRef cfTimer, void* context)
 {
     TimerBase* timer = static_cast<TimerBase*>(context);
 
     AutodrainedPool pool;
+
+    if (!CFRunLoopTimerDoesRepeat(cfTimer))
+        timer->stop();
+
     timer->fired();
 }
 
index 64060c4..c950c57 100644 (file)
 #endif
 
 #include <wtf/RunLoop.h>
-#include <wtf/NeverDestroyed.h>
-#if USE(GLIB)
-#include <wtf/glib/RunLoopSourcePriority.h>
-#endif
 
 namespace WTF {
 
@@ -48,31 +44,6 @@ namespace WTF {
 static pthread_t mainThread;
 #endif
 
-class MainThreadDispatcher {
-    WTF_MAKE_FAST_ALLOCATED;
-public:
-    MainThreadDispatcher()
-        : m_timer(RunLoop::main(), this, &MainThreadDispatcher::fired)
-    {
-#if USE(GLIB)
-        m_timer.setPriority(RunLoopSourcePriority::MainThreadDispatcherTimer);
-#endif
-    }
-
-    void schedule()
-    {
-        m_timer.startOneShot(0_s);
-    }
-
-private:
-    void fired()
-    {
-        dispatchFunctionsFromMainThread();
-    }
-
-    RunLoop::Timer<MainThreadDispatcher> m_timer;
-};
-
 void initializeMainThreadPlatform()
 {
 #if !HAVE(PTHREAD_MAIN_NP)
@@ -91,10 +62,7 @@ bool isMainThread()
 
 void scheduleDispatchFunctionsOnMainThread()
 {
-    // Use a RunLoop::Timer instead of RunLoop::dispatch() to be able to use a different priority and
-    // avoid the double queue because dispatchOnMainThread also queues the functions.
-    static NeverDestroyed<MainThreadDispatcher> dispatcher;
-    dispatcher.get().schedule();
+    RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
 }
 
 } // namespace WTF
index 9c64695..e73f514 100644 (file)
@@ -48,9 +48,6 @@ enum RunLoopSourcePriority {
     // Garbage collector timers.
     JavascriptTimer = 200,
 
-    // callOnMainThread.
-    MainThreadDispatcherTimer = 100,
-
     // Memory pressure monitor.
     MemoryPressureHandlerTimer = -100,
 
@@ -88,8 +85,6 @@ enum RunLoopSourcePriority {
     RunLoopDispatcher = 0,
     RunLoopTimer = 0,
 
-    MainThreadDispatcherTimer = 10,
-
     MemoryPressureHandlerTimer = -10,
 
     JavascriptTimer = 10,
index 07695bb..c06f8b6 100644 (file)
 
 namespace WTF {
 
-static HWND threadingWindowHandle;
-static UINT threadingFiredMessage;
-const LPCWSTR kThreadingWindowClassName = L"ThreadingWindowClass";
 static ThreadIdentifier mainThread { 0 };
 
-LRESULT CALLBACK ThreadingWindowWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
-{
-    if (message == threadingFiredMessage)
-        dispatchFunctionsFromMainThread();
-    else
-        return DefWindowProc(hWnd, message, wParam, lParam);
-    return 0;
-}
-
 void initializeMainThreadPlatform()
 {
-    if (threadingWindowHandle)
-        return;
-
-    WNDCLASSW wcex;
-    memset(&wcex, 0, sizeof(WNDCLASSW));
-    wcex.lpfnWndProc    = ThreadingWindowWndProc;
-    wcex.lpszClassName  = kThreadingWindowClassName;
-    RegisterClassW(&wcex);
-
-    threadingWindowHandle = CreateWindowW(kThreadingWindowClassName, nullptr, 0,
-        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, HWND_MESSAGE, nullptr, nullptr, nullptr);
-    threadingFiredMessage = RegisterWindowMessageW(L"com.apple.WebKit.MainThreadFired");
-
     mainThread = Thread::currentID();
-
     Thread::initializeCurrentThreadInternal("Main Thread");
     RunLoop::registerRunLoopMessageWindowClass();
 }
@@ -79,8 +53,7 @@ bool isMainThread()
 
 void scheduleDispatchFunctionsOnMainThread()
 {
-    ASSERT(threadingWindowHandle);
-    PostMessage(threadingWindowHandle, threadingFiredMessage, 0, 0);
+    RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
 }
 
 } // namespace WTF