Changeset 262863 in webkit


Ignore:
Timestamp:
Jun 10, 2020 3:03:12 PM (4 years ago)
Author:
ggaren@apple.com
Message:

[Cocoa] Build callOnMainThread on WTF::RunLoop rather than on NSObject methods
https://bugs.webkit.org/show_bug.cgi?id=213043

Reviewed by Simon Fraser.

Original patch by Sihui Liu.

From https://bugs.webkit.org/show_bug.cgi?id=202874, this is the subset
of Sihui's patch that unifies some of RunLoop and callOnMainThread.

My goal is to simplify the code, and shrink the diff when testing
CFRunLoopSource1 in the future.

  • wtf/RunLoop.cpp:

(WTF::RunLoop::initializeWebRunLoop):
(WTF::RunLoop::web):

  • wtf/RunLoop.h:
  • wtf/cocoa/MainThreadCocoa.mm:

(WTF::initializeMainThreadPlatform):
(WTF::scheduleDispatchFunctionsOnMainThread):
(WTF::initializeWebThread):
(-[JSWTFMainThreadCaller call]): Deleted.

Location:
trunk/Source/WTF
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r262858 r262863  
     12020-06-10  Geoffrey Garen  <ggaren@apple.com>
     2
     3        [Cocoa] Build callOnMainThread on WTF::RunLoop rather than on NSObject methods
     4        https://bugs.webkit.org/show_bug.cgi?id=213043
     5
     6        Reviewed by Simon Fraser.
     7
     8        Original patch by Sihui Liu.
     9
     10        From https://bugs.webkit.org/show_bug.cgi?id=202874, this is the subset
     11        of Sihui's patch that unifies some of RunLoop and callOnMainThread.
     12
     13        My goal is to simplify the code, and shrink the diff when testing
     14        CFRunLoopSource1 in the future.
     15
     16        * wtf/RunLoop.cpp:
     17        (WTF::RunLoop::initializeWebRunLoop):
     18        (WTF::RunLoop::web):
     19        * wtf/RunLoop.h:
     20        * wtf/cocoa/MainThreadCocoa.mm:
     21        (WTF::initializeMainThreadPlatform):
     22        (WTF::scheduleDispatchFunctionsOnMainThread):
     23        (WTF::initializeWebThread):
     24        (-[JSWTFMainThreadCaller call]): Deleted.
     25
    1262020-06-10  Jer Noble  <jer.noble@apple.com>
    227
  • trunk/Source/WTF/wtf/RunLoop.cpp

    r257142 r262863  
    3434
    3535static RunLoop* s_mainRunLoop;
     36#if USE(WEB_THREAD)
     37static RunLoop* s_webRunLoop;
     38#endif
    3639
    3740// Helper class for ThreadSpecificData.
     
    6972    return *s_mainRunLoop;
    7073}
     74
     75#if USE(WEB_THREAD)
     76void RunLoop::initializeWebRunLoop()
     77{
     78    s_webRunLoop = &RunLoop::current();
     79}
     80
     81RunLoop& RunLoop::web()
     82{
     83    ASSERT(s_webRunLoop);
     84    return *s_webRunLoop;
     85}
     86#endif
    7187
    7288bool RunLoop::isMain()
  • trunk/Source/WTF/wtf/RunLoop.h

    r261569 r262863  
    6262    // can be called from any thread).
    6363    WTF_EXPORT_PRIVATE static void initializeMainRunLoop();
     64#if USE(WEB_THREAD)
     65    WTF_EXPORT_PRIVATE static void initializeWebRunLoop();
     66#endif
    6467
    6568    WTF_EXPORT_PRIVATE static RunLoop& current();
    6669    WTF_EXPORT_PRIVATE static RunLoop& main();
     70#if USE(WEB_THREAD)
     71    WTF_EXPORT_PRIVATE static RunLoop& web();
     72#endif
    6773    WTF_EXPORT_PRIVATE static bool isMain();
    6874    ~RunLoop() final;
  • trunk/Source/WTF/wtf/cocoa/MainThreadCocoa.mm

    r260366 r262863  
    3737#import <wtf/HashSet.h>
    3838#import <wtf/RetainPtr.h>
     39#import <wtf/RunLoop.h>
    3940#import <wtf/SchedulePair.h>
    4041#import <wtf/Threading.h>
     
    4344#import <wtf/ios/WebCoreThread.h>
    4445#endif
    45 
    46 @interface JSWTFMainThreadCaller : NSObject
    47 - (void)call;
    48 @end
    49 
    50 @implementation JSWTFMainThreadCaller
    51 
    52 - (void)call
    53 {
    54     WTF::dispatchFunctionsFromMainThread();
    55 }
    56 
    57 @end
    5846
    5947#define LOG_CHANNEL_PREFIX Log
     
    6755#endif
    6856
    69 
    70 static JSWTFMainThreadCaller* staticMainThreadCaller;
    7157static bool isTimerPosted; // This is only accessed on the main thread.
    7258
     
    8571        RELEASE_LOG_FAULT(Threading, "WebKit Threading Violation - initial use of WebKit from a secondary thread.");
    8672    ASSERT(pthread_main_np());
    87 
    88     ASSERT(!staticMainThreadCaller);
    89     staticMainThreadCaller = [[JSWTFMainThreadCaller alloc] init];
    9073}
    9174
     
    11396void scheduleDispatchFunctionsOnMainThread()
    11497{
    115     ASSERT(staticMainThreadCaller);
    116    
    11798#if USE(WEB_THREAD)
    11899    if (isWebThread()) {
     
    122103
    123104    if (mainThreadPthread) {
    124         [staticMainThreadCaller performSelector:@selector(call) onThread:mainThreadNSThread withObject:nil waitUntilDone:NO];
     105        RunLoop::web().dispatch(dispatchFunctionsFromMainThread);
    125106        return;
    126107    }
     
    132113#endif
    133114
    134     [staticMainThreadCaller performSelectorOnMainThread:@selector(call) withObject:nil waitUntilDone:NO];
     115    RunLoop::main().dispatch(dispatchFunctionsFromMainThread);
    135116}
    136117
     
    197178        mainThreadNSThread = [NSThread currentThread];
    198179        sWebThread = &Thread::current();
     180        RunLoop::initializeWebRunLoop();
    199181    });
    200182}
Note: See TracChangeset for help on using the changeset viewer.