Changeset 117018 in webkit


Ignore:
Timestamp:
May 14, 2012 5:05:12 PM (12 years ago)
Author:
aestes@apple.com
Message:

Move the parts of RunLoopMac.mm that aren't Mac-specific into RunLoopCF.cpp
https://bugs.webkit.org/show_bug.cgi?id=86411

Reviewed by Anders Carlsson.

Most of RunLoopMac.mm was written in terms of CF API. Move these bits
to a new file called RunLoopCF.cpp, leaving only the bits dealing with
NSApplication.

  • WebCore.xcodeproj/project.pbxproj: Xcode decided to give

VisitedLinks.* new UUIDs. I'll allow it.

  • platform/cf/RunLoopCF.cpp: Copied from Source/WebCore/platform/mac/RunLoopMac.mm.
  • platform/mac/RunLoopMac.mm:
Location:
trunk/Source/WebCore
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r117016 r117018  
     12012-05-14  Andy Estes  <aestes@apple.com>
     2
     3        Move the parts of RunLoopMac.mm that aren't Mac-specific into RunLoopCF.cpp
     4        https://bugs.webkit.org/show_bug.cgi?id=86411
     5
     6        Reviewed by Anders Carlsson.
     7
     8        Most of RunLoopMac.mm was written in terms of CF API. Move these bits
     9        to a new file called RunLoopCF.cpp, leaving only the bits dealing with
     10        NSApplication.
     11
     12        * WebCore.xcodeproj/project.pbxproj: Xcode decided to give
     13        VisitedLinks.* new UUIDs. I'll allow it.
     14        * platform/cf/RunLoopCF.cpp: Copied from Source/WebCore/platform/mac/RunLoopMac.mm.
     15        * platform/mac/RunLoopMac.mm:
     16
    1172012-05-14  Erik Arvidsson  <arv@chromium.org>
    218
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r116974 r117018  
    724724                293EAE211356B32E0067ACF9 /* RuntimeApplicationChecks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 293EAE201356B32E0067ACF9 /* RuntimeApplicationChecks.cpp */; };
    725725                29489FC712C00F0300D83F0F /* AccessibilityScrollView.h in Headers */ = {isa = PBXBuildFile; fileRef = 29489FC512C00F0300D83F0F /* AccessibilityScrollView.h */; };
     726                29A309AC1561C99B00BBD8E5 /* RunLoopCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29A309AB1561C99B00BBD8E5 /* RunLoopCF.cpp */; };
     727                29A309B01561CAC400BBD8E5 /* VisitedLinks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29A309AE1561CAC400BBD8E5 /* VisitedLinks.cpp */; };
     728                29A309B11561CAC400BBD8E5 /* VisitedLinks.h in Headers */ = {isa = PBXBuildFile; fileRef = 29A309AF1561CAC400BBD8E5 /* VisitedLinks.h */; };
    726729                29A8122B0FBB9C1D00510293 /* AccessibilityTable.h in Headers */ = {isa = PBXBuildFile; fileRef = 29A8120D0FBB9C1D00510293 /* AccessibilityTable.h */; };
    727730                29A8122C0FBB9C1D00510293 /* AccessibilityList.h in Headers */ = {isa = PBXBuildFile; fileRef = 29A8120E0FBB9C1D00510293 /* AccessibilityList.h */; };
     
    76517654                2981CAAE131822EC00D12F2A /* AccessibilityTableRow.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AccessibilityTableRow.cpp; sourceTree = "<group>"; };
    76527655                2981CAAF131822EC00D12F2A /* AXObjectCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AXObjectCache.cpp; sourceTree = "<group>"; };
     7656                29A309AB1561C99B00BBD8E5 /* RunLoopCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoopCF.cpp; sourceTree = "<group>"; };
     7657                29A309AE1561CAC400BBD8E5 /* VisitedLinks.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VisitedLinks.cpp; sourceTree = "<group>"; };
     7658                29A309AF1561CAC400BBD8E5 /* VisitedLinks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VisitedLinks.h; sourceTree = "<group>"; };
    76537659                29A8120D0FBB9C1D00510293 /* AccessibilityTable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilityTable.h; sourceTree = "<group>"; };
    76547660                29A8120E0FBB9C1D00510293 /* AccessibilityList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilityList.h; sourceTree = "<group>"; };
     
    1416614172                                5160306B0CC4362300C8AC25 /* FileSystemCF.cpp */,
    1416714173                                1A98956A0AA78F80005EF5EF /* KURLCFNet.cpp */,
     14174                                29A309AB1561C99B00BBD8E5 /* RunLoopCF.cpp */,
    1416814175                                1C63A2470F71646600C09D5A /* RunLoopTimerCF.cpp */,
    1416914176                                1CEFC9B80D78DC8C007D2579 /* SchedulePair.cpp */,
     
    2039620403                                2E3BBF061162DA1100B9409A /* UUID.h */,
    2039720404                                515788C01207852C00A37C4A /* VisitedLinkStrategy.h */,
    20398                                 D6FDAEF2149C06190037B1E5 /* VisitedLinks.cpp */,
    20399                                 D630E2AB149BF344005B2F97 /* VisitedLinks.h */,
     20405                                29A309AE1561CAC400BBD8E5 /* VisitedLinks.cpp */,
     20406                                29A309AF1561CAC400BBD8E5 /* VisitedLinks.h */,
    2040020407                                9380F47109A11AB4001FDB34 /* Widget.cpp */,
    2040120408                                9380F47209A11AB4001FDB34 /* Widget.h */,
     
    2472224729                                A883DF280F3D045D00F19BF6 /* VisibleSelection.h in Headers */,
    2472324730                                515788C11207852C00A37C4A /* VisitedLinkStrategy.h in Headers */,
    24724                                 D630E2AC149BF344005B2F97 /* VisitedLinks.h in Headers */,
    2472524731                                E44613B60CD6344E00FADA75 /* VoidCallback.h in Headers */,
    2472624732                                FD7F299213D4C0CB00AD9535 /* WaveShaperDSPKernel.h in Headers */,
     
    2488824894                                B658FFA21522EF3A00DD5595 /* JSRadioNodeList.h in Headers */,
    2488924895                                B658FFA61522EFAA00DD5595 /* RadioNodeList.h in Headers */,
     24896                                29A309B11561CAC400BBD8E5 /* VisitedLinks.h in Headers */,
    2489024897                        );
    2489124898                        runOnlyForDeploymentPostprocessing = 0;
     
    2776127768                                93309E1F099E64920056E581 /* VisiblePosition.cpp in Sources */,
    2776227769                                A883DF270F3D045D00F19BF6 /* VisibleSelection.cpp in Sources */,
    27763                                 D6FDAEF3149C06190037B1E5 /* VisitedLinks.cpp in Sources */,
    2776427770                                FD7F299113D4C0CB00AD9535 /* WaveShaperDSPKernel.cpp in Sources */,
    2776527771                                FD7F299313D4C0CB00AD9535 /* WaveShaperNode.cpp in Sources */,
     
    2791027916                                B658FFA11522EF3A00DD5595 /* JSRadioNodeList.cpp in Sources */,
    2791127917                                B658FFA51522EFAA00DD5595 /* RadioNodeList.cpp in Sources */,
     27918                                29A309AC1561C99B00BBD8E5 /* RunLoopCF.cpp in Sources */,
     27919                                29A309B01561CAC400BBD8E5 /* VisitedLinks.cpp in Sources */,
    2791227920                        );
    2791327921                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/platform/cf/RunLoopCF.cpp

    r117016 r117018  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2012 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import "config.h"
    27 #import "RunLoop.h"
     26#include "config.h"
     27#include "RunLoop.h"
    2828
    29 #import <dispatch/dispatch.h>
     29#include "AutodrainedPool.h"
     30#include <CoreFoundation/CoreFoundation.h>
     31#include <dispatch/dispatch.h>
    3032
    3133namespace WebCore {
    32 
     34   
    3335static RunLoop* s_mainRunLoop;
    3436
     
    4547    if (pthread_main_np())
    4648        return RunLoop::main();
    47 
     49   
    4850    DEFINE_STATIC_LOCAL(WTF::ThreadSpecific<RunLoop>, runLoopData, ());
    4951    return &*runLoopData;
     
    5860void RunLoop::performWork(void* context)
    5961{
    60     // Wrap main thread in an Autorelease pool.  Sending messages can call
     62    // Wrap main thread in an Autorelease pool. Sending messages can call
    6163    // into objc code and accumulate memory. 
    6264    if (current() == main()) {
    63         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     65        AutodrainedPool pool;
    6466        static_cast<RunLoop*>(context)->performWork();
    65         [pool drain];
    6667    } else
    6768        static_cast<RunLoop*>(context)->performWork();
     
    9394}
    9495
    95 void RunLoop::run()
    96 {
    97     current()->m_nestingLevel++;
    98     if (current() == main() && current()->m_nestingLevel == 1) {
    99         // Use -[NSApplication run] for the main run loop.
    100         [NSApp run];
    101     } else {
    102         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    103         CFRunLoopRun();
    104         [pool drain];
    105     }
    106     current()->m_nestingLevel--;
    107 }
    108 
    10996void RunLoop::runForDuration(double duration)
    11097{
    11198    CFRunLoopRunInMode(kCFRunLoopDefaultMode, duration, true);
    112 }
    113 
    114 void RunLoop::stop()
    115 {
    116     ASSERT(m_runLoop == CFRunLoopGetCurrent());
    117    
    118     if (m_runLoop == main()->m_runLoop && m_nestingLevel == 1) {
    119         [[NSApplication sharedApplication] stop:nil];
    120         NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined
    121                                             location:NSMakePoint(0, 0)
    122                                        modifierFlags:0
    123                                            timestamp:0.0
    124                                          windowNumber:0
    125                                              context:nil
    126                                              subtype: 0
    127                                                data1:0
    128                                                data2:0];
    129         [NSApp postEvent:event atStart:true];
    130     } else
    131         CFRunLoopStop(m_runLoop);
    13299}
    133100
     
    138105}
    139106
     107#if !PLATFORM(MAC) || PLATFORM(IOS)
     108void RunLoop::run()
     109{
     110    current()->m_nestingLevel++;
     111   
     112    {
     113        AutodrainedPool pool;
     114        CFRunLoopRun();
     115    }
     116   
     117    current()->m_nestingLevel--;
     118}
     119
     120void RunLoop::stop()
     121{
     122    ASSERT(m_runLoop == CFRunLoopGetCurrent());
     123    CFRunLoopStop(m_runLoop);
     124}
     125#endif
     126
    140127// RunLoop::Timer
    141128
     
    144131    TimerBase* timer = static_cast<TimerBase*>(context);
    145132   
    146     // Wrap main thread in an Autorelease pool.  The timer can call
     133    // Wrap main thread in an Autorelease pool. The timer can call
    147134    // into objc code and accumulate memory outside of the main event loop.
    148135    if (current() == main()) {
    149         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     136        AutodrainedPool pool;
    150137        timer->fired();
    151         [pool drain];
    152138    } else
    153139        timer->fired();
     
    169155    if (m_timer)
    170156        stop();
    171 
     157   
    172158    CFRunLoopTimerContext context = { 0, this, 0, 0, 0 };
    173159    CFTimeInterval repeatInterval = repeat ? nextFireInterval : 0;
     
    180166    if (!m_timer)
    181167        return;
    182 
     168   
    183169    CFRunLoopTimerInvalidate(m_timer);
    184170    CFRelease(m_timer);
  • trunk/Source/WebCore/platform/mac/RunLoopMac.mm

    r110277 r117018  
    2727#import "RunLoop.h"
    2828
    29 #import <dispatch/dispatch.h>
    30 
    3129namespace WebCore {
    32 
    33 static RunLoop* s_mainRunLoop;
    34 
    35 void RunLoop::initializeMainRunLoop()
    36 {
    37     static dispatch_once_t onceToken;
    38     dispatch_once(&onceToken, ^{
    39         s_mainRunLoop = new RunLoop(CFRunLoopGetMain());
    40     });
    41 }
    42 
    43 RunLoop* RunLoop::current()
    44 {
    45     if (pthread_main_np())
    46         return RunLoop::main();
    47 
    48     DEFINE_STATIC_LOCAL(WTF::ThreadSpecific<RunLoop>, runLoopData, ());
    49     return &*runLoopData;
    50 }
    51 
    52 RunLoop* RunLoop::main()
    53 {
    54     ASSERT(s_mainRunLoop);
    55     return s_mainRunLoop;
    56 }
    57 
    58 void RunLoop::performWork(void* context)
    59 {
    60     // Wrap main thread in an Autorelease pool.  Sending messages can call
    61     // into objc code and accumulate memory. 
    62     if (current() == main()) {
    63         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    64         static_cast<RunLoop*>(context)->performWork();
    65         [pool drain];
    66     } else
    67         static_cast<RunLoop*>(context)->performWork();
    68 }
    69 
    70 RunLoop::RunLoop()
    71     : m_runLoop(CFRunLoopGetCurrent())
    72     , m_nestingLevel(0)
    73 {
    74     CFRunLoopSourceContext context = { 0, this, 0, 0, 0, 0, 0, 0, 0, performWork };
    75     m_runLoopSource = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &context);
    76     CFRunLoopAddSource(m_runLoop, m_runLoopSource, kCFRunLoopCommonModes);
    77 }
    78 
    79 RunLoop::RunLoop(CFRunLoopRef runLoop)
    80     : m_runLoop(runLoop)
    81     , m_nestingLevel(0)
    82 {
    83     CFRunLoopSourceContext context = { 0, this, 0, 0, 0, 0, 0, 0, 0, performWork };
    84     m_runLoopSource = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &context);
    85     CFRunLoopAddSource(m_runLoop, m_runLoopSource, kCFRunLoopCommonModes);
    86 }
    87 
    88 RunLoop::~RunLoop()
    89 {
    90     // FIXME: Tear down the work item queue here.
    91     CFRunLoopSourceInvalidate(m_runLoopSource);
    92     CFRelease(m_runLoopSource);
    93 }
    9430
    9531void RunLoop::run()
     
    10541    }
    10642    current()->m_nestingLevel--;
    107 }
    108 
    109 void RunLoop::runForDuration(double duration)
    110 {
    111     CFRunLoopRunInMode(kCFRunLoopDefaultMode, duration, true);
    11243}
    11344
     
    13263}
    13364
    134 void RunLoop::wakeUp()
    135 {
    136     CFRunLoopSourceSignal(m_runLoopSource);
    137     CFRunLoopWakeUp(m_runLoop);
    138 }
    139 
    140 // RunLoop::Timer
    141 
    142 void RunLoop::TimerBase::timerFired(CFRunLoopTimerRef, void* context)
    143 {
    144     TimerBase* timer = static_cast<TimerBase*>(context);
    145    
    146     // Wrap main thread in an Autorelease pool.  The timer can call
    147     // into objc code and accumulate memory outside of the main event loop.
    148     if (current() == main()) {
    149         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    150         timer->fired();
    151         [pool drain];
    152     } else
    153         timer->fired();
    154 }
    155 
    156 RunLoop::TimerBase::TimerBase(RunLoop* runLoop)
    157     : m_runLoop(runLoop)
    158     , m_timer(0)
    159 {
    160 }
    161 
    162 RunLoop::TimerBase::~TimerBase()
    163 {
    164     stop();
    165 }
    166 
    167 void RunLoop::TimerBase::start(double nextFireInterval, bool repeat)
    168 {
    169     if (m_timer)
    170         stop();
    171 
    172     CFRunLoopTimerContext context = { 0, this, 0, 0, 0 };
    173     CFTimeInterval repeatInterval = repeat ? nextFireInterval : 0;
    174     m_timer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + nextFireInterval, repeatInterval, 0, 0, timerFired, &context);
    175     CFRunLoopAddTimer(m_runLoop->m_runLoop, m_timer, kCFRunLoopCommonModes);
    176 }
    177 
    178 void RunLoop::TimerBase::stop()
    179 {
    180     if (!m_timer)
    181         return;
    182 
    183     CFRunLoopTimerInvalidate(m_timer);
    184     CFRelease(m_timer);
    185     m_timer = 0;
    186 }
    187 
    188 bool RunLoop::TimerBase::isActive() const
    189 {
    190     return m_timer && CFRunLoopTimerIsValid(m_timer);
    191 }
    192 
    19365} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.