Changeset 262904 in webkit


Ignore:
Timestamp:
Jun 11, 2020 9:28:32 AM (4 years ago)
Author:
ggaren@apple.com
Message:

[Cocoa] Build callOnMainThread on WTF::RunLoop rather than on a timer
https://bugs.webkit.org/show_bug.cgi?id=213063

Reviewed by Anders Carlsson.

Always use the RunLoop API for main thread tasks.

Previously, callOnMainThread sometimes scheduled a timer and sometimes
used the RunLoop. (Ironically, the timer behavior was added in r55816
with the intention to establish a single point of execution. Now, it has
the opposite effect.)

I picked the RunLoop API rather than the timer API because it moves us
closer to universally applying the RunLoop speedup in
https://bugs.webkit.org/show_bug.cgi?id=202874. Also, it avoids
allocating a timer, which can be expensive.

  • wtf/cocoa/MainThreadCocoa.mm:

(WTF::scheduleDispatchFunctionsOnMainThread): The webIfExists() check
is a superset of the isWebThread() check, so we can just remove the
isWebThread() check when scheduling tasks to the web thread.
(WTF::timerFired): Deleted.
(WTF::postTimer): Deleted.

Location:
trunk/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r262878 r262904  
     12020-06-11  Geoffrey Garen  <ggaren@apple.com>
     2
     3        [Cocoa] Build callOnMainThread on WTF::RunLoop rather than on a timer
     4        https://bugs.webkit.org/show_bug.cgi?id=213063
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Always use the RunLoop API for main thread tasks.
     9
     10        Previously, callOnMainThread sometimes scheduled a timer and sometimes
     11        used the RunLoop. (Ironically, the timer behavior was added in r55816
     12        with the intention to establish a single point of execution. Now, it has
     13        the opposite effect.)
     14
     15        I picked the RunLoop API rather than the timer API because it moves us
     16        closer to universally applying the RunLoop speedup in
     17        https://bugs.webkit.org/show_bug.cgi?id=202874. Also, it avoids
     18        allocating a timer, which can be expensive.
     19
     20        * wtf/cocoa/MainThreadCocoa.mm:
     21        (WTF::scheduleDispatchFunctionsOnMainThread): The webIfExists() check
     22        is a superset of the isWebThread() check, so we can just remove the
     23        isWebThread() check when scheduling tasks to the web thread.
     24        (WTF::timerFired): Deleted.
     25        (WTF::postTimer): Deleted.
     26
    1272020-06-10  Geoffrey Garen  <ggaren@apple.com>
    228
  • trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm

    r262878 r262904  
    5555#endif
    5656
    57 static bool isTimerPosted; // This is only accessed on the main thread.
    58 
    5957#if USE(WEB_THREAD)
    6058// When the Web thread is enabled, we consider it to be the main thread, not pthread main.
     
    7270}
    7371
    74 static void timerFired(CFRunLoopTimerRef timer, void*)
    75 {
    76     CFRelease(timer);
    77     isTimerPosted = false;
    78 
    79     @autoreleasepool {
    80         WTF::dispatchFunctionsFromMainThread();
    81     }
    82 }
    83 
    84 static void postTimer()
    85 {
    86     ASSERT(isMainThread());
    87 
    88     if (isTimerPosted)
    89         return;
    90 
    91     isTimerPosted = true;
    92     CFRunLoopAddTimer(CFRunLoopGetCurrent(), CFRunLoopTimerCreate(0, 0, 0, 0, 0, timerFired, 0), kCFRunLoopCommonModes);
    93 }
    94 
    9572void scheduleDispatchFunctionsOnMainThread()
    9673{
    9774#if USE(WEB_THREAD)
    98     if (isWebThread()) {
    99         postTimer();
    100         return;
    101     }
    102 
    10375    if (auto* webRunLoop = RunLoop::webIfExists()) {
    10476        webRunLoop->dispatch(dispatchFunctionsFromMainThread);
    105         return;
    106     }
    107 #else
    108     if (isMainThread()) {
    109         postTimer();
    11077        return;
    11178    }
Note: See TracChangeset for help on using the changeset viewer.