Changeset 263723 in webkit


Ignore:
Timestamp:
Jun 29, 2020 9:25:52 PM (4 years ago)
Author:
ggaren@apple.com
Message:

[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.

Location:
trunk/Source/WTF
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r263718 r263723  
     12020-06-29  Geoffrey Garen  <ggaren@apple.com>
     2
     3        [GTK] [Win] Build callOnMainThread on WTF::RunLoop rather than on a timer
     4        https://bugs.webkit.org/show_bug.cgi?id=213694
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        As of https://bugs.webkit.org/show_bug.cgi?id=213063, Darwin platforms
     9        use the RunLoop. Let's match them for consistency, and to delete some
     10        code.
     11
     12        * wtf/generic/MainThreadGeneric.cpp:
     13        (WTF::scheduleDispatchFunctionsOnMainThread):
     14        (WTF::MainThreadDispatcher::MainThreadDispatcher): Deleted.
     15        (WTF::MainThreadDispatcher::schedule): Deleted.
     16        (WTF::MainThreadDispatcher::fired): Deleted.
     17        * wtf/glib/RunLoopSourcePriority.h:
     18        * wtf/win/MainThreadWin.cpp:
     19        (WTF::initializeMainThreadPlatform):
     20        (WTF::scheduleDispatchFunctionsOnMainThread):
     21        (WTF::ThreadingWindowWndProc): Deleted.
     22
    1232020-06-29  Guowei Yang  <guowei_yang@apple.com>
    224
  • trunk/Source/WTF/wtf/cf/RunLoopCF.cpp

    r252124 r263723  
    8484// RunLoop::Timer
    8585
    86 void RunLoop::TimerBase::timerFired(CFRunLoopTimerRef, void* context)
     86void RunLoop::TimerBase::timerFired(CFRunLoopTimerRef cfTimer, void* context)
    8787{
    8888    TimerBase* timer = static_cast<TimerBase*>(context);
    8989
    9090    AutodrainedPool pool;
     91
     92    if (!CFRunLoopTimerDoesRepeat(cfTimer))
     93        timer->stop();
     94
    9195    timer->fired();
    9296}
  • trunk/Source/WTF/wtf/generic/MainThreadGeneric.cpp

    r251164 r263723  
    3838
    3939#include <wtf/RunLoop.h>
    40 #include <wtf/NeverDestroyed.h>
    41 #if USE(GLIB)
    42 #include <wtf/glib/RunLoopSourcePriority.h>
    43 #endif
    4440
    4541namespace WTF {
     
    4844static pthread_t mainThread;
    4945#endif
    50 
    51 class MainThreadDispatcher {
    52     WTF_MAKE_FAST_ALLOCATED;
    53 public:
    54     MainThreadDispatcher()
    55         : m_timer(RunLoop::main(), this, &MainThreadDispatcher::fired)
    56     {
    57 #if USE(GLIB)
    58         m_timer.setPriority(RunLoopSourcePriority::MainThreadDispatcherTimer);
    59 #endif
    60     }
    61 
    62     void schedule()
    63     {
    64         m_timer.startOneShot(0_s);
    65     }
    66 
    67 private:
    68     void fired()
    69     {
    70         dispatchFunctionsFromMainThread();
    71     }
    72 
    73     RunLoop::Timer<MainThreadDispatcher> m_timer;
    74 };
    7546
    7647void initializeMainThreadPlatform()
     
    9263void scheduleDispatchFunctionsOnMainThread()
    9364{
    94     // Use a RunLoop::Timer instead of RunLoop::dispatch() to be able to use a different priority and
    95     // avoid the double queue because dispatchOnMainThread also queues the functions.
    96     static NeverDestroyed<MainThreadDispatcher> dispatcher;
    97     dispatcher.get().schedule();
     65    RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
    9866}
    9967
  • trunk/Source/WTF/wtf/glib/RunLoopSourcePriority.h

    r262973 r263723  
    4949    JavascriptTimer = 200,
    5050
    51     // callOnMainThread.
    52     MainThreadDispatcherTimer = 100,
    53 
    5451    // Memory pressure monitor.
    5552    MemoryPressureHandlerTimer = -100,
     
    8986    RunLoopTimer = 0,
    9087
    91     MainThreadDispatcherTimer = 10,
    92 
    9388    MemoryPressureHandlerTimer = -10,
    9489
  • trunk/Source/WTF/wtf/win/MainThreadWin.cpp

    r261393 r263723  
    3838namespace WTF {
    3939
    40 static HWND threadingWindowHandle;
    41 static UINT threadingFiredMessage;
    42 const LPCWSTR kThreadingWindowClassName = L"ThreadingWindowClass";
    4340static ThreadIdentifier mainThread { 0 };
    44 
    45 LRESULT CALLBACK ThreadingWindowWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    46 {
    47     if (message == threadingFiredMessage)
    48         dispatchFunctionsFromMainThread();
    49     else
    50         return DefWindowProc(hWnd, message, wParam, lParam);
    51     return 0;
    52 }
    5341
    5442void initializeMainThreadPlatform()
    5543{
    56     if (threadingWindowHandle)
    57         return;
    58 
    59     WNDCLASSW wcex;
    60     memset(&wcex, 0, sizeof(WNDCLASSW));
    61     wcex.lpfnWndProc    = ThreadingWindowWndProc;
    62     wcex.lpszClassName  = kThreadingWindowClassName;
    63     RegisterClassW(&wcex);
    64 
    65     threadingWindowHandle = CreateWindowW(kThreadingWindowClassName, nullptr, 0,
    66         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, HWND_MESSAGE, nullptr, nullptr, nullptr);
    67     threadingFiredMessage = RegisterWindowMessageW(L"com.apple.WebKit.MainThreadFired");
    68 
    6944    mainThread = Thread::currentID();
    70 
    7145    Thread::initializeCurrentThreadInternal("Main Thread");
    7246    RunLoop::registerRunLoopMessageWindowClass();
     
    8054void scheduleDispatchFunctionsOnMainThread()
    8155{
    82     ASSERT(threadingWindowHandle);
    83     PostMessage(threadingWindowHandle, threadingFiredMessage, 0, 0);
     56    RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
    8457}
    8558
Note: See TracChangeset for help on using the changeset viewer.