⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181671 in webkit


Ignore:
Timestamp:
Mar 17, 2015, 4:42:46 PM (11 years ago)
Author:
Chris Dumez
Message:

[Mac][iOS] setSharedTimerFireInterval() / stopSharedTimer() are expensive
https://bugs.webkit.org/show_bug.cgi?id=142752
<rdar://problem/20176731>

Reviewed by Antti Koivisto.

setSharedTimerFireInterval() / stopSharedTimer() are expensive on Mac
and iOS on pages using a lot of timers.

For example, on bing.com / iOS, ~15.4% of the CPU time is spent in
setSharedTimerFireInterval() and ~14.7% of the CPU time is spent in
stopSharedTimer(). The expensive calls are CFRunLoopAddTimer (11.4%),
CFRunLoopTimerInvalidate (14.1%), CFRunLoopTimerCreate (3.3%).

The issue is that we keep creating, adding to run loop modes, and then
destroying the sharedTimer for each firing event. This is very
expensive. In such case, the CFRunLoopTimerRef documentation advises to
"""
... create a repeating timer with an initial firing time in the distant
future (or the initial firing time) and a very large repeat interval—on
the order of decades or more—and add it to all the necessary run loop
modes. Then, when you know when the timer should fire next, you reset
the firing time with CFRunLoopTimerSetNextFireDate, perhaps from the
timer’s own callback function. This technique effectively produces a
reusable, asynchronous timer.
""" [1].

Doing so greatly decreases CPU time spend in:

  • setSharedTimerFireInterval(): 15.4% -> 4.6%
  • stopSharedTimer(): 14.6% -> 8.6%

Overall CPU time spent on bing.com in timerFired() goes down from
~61.2% to ~49.5%.

This patch also refactors the SharedTimer code to share as much as
possible between Mac and iOS.

This patch is based in part on the following patch:
http://trac.webkit.org/changeset/143210

[1] https://developer.apple.com/library/prerelease/ios/documentation/CoreFoundation/Reference/CFRunLoopTimerRef/index.html#//apple_ref/c/func/CFRunLoopTimerSetNextFireDate

  • WebCore.xcodeproj/project.pbxproj:
  • platform/SharedTimer.h:

(WebCore::SharedTimer::invalidate):
(WebCore::MainThreadSharedTimer::setFiredFunction): Deleted.
(WebCore::MainThreadSharedTimer::setFireInterval): Deleted.
(WebCore::MainThreadSharedTimer::stop): Deleted.

  • platform/ThreadTimers.cpp:

(WebCore::ThreadTimers::fireTimersInNestedEventLoop):

  • platform/cf/SharedTimerCF.mm: Added.

(WebCore::applicationDidBecomeActive):
(WebCore::setupPowerObserver):
(WebCore::setSharedTimerFiredFunction):
(WebCore::timerFired):
(WebCore::restartSharedTimer):
(WebCore::invalidateSharedTimer):
(WebCore::setSharedTimerFireInterval):
(WebCore::stopSharedTimer):

  • platform/efl/SharedTimerEfl.cpp:

(WebCore::invalidateSharedTimer):

  • platform/gtk/SharedTimerGtk.cpp:

(WebCore::invalidateSharedTimer):

  • platform/ios/SharedTimerIOS.mm: Removed.
  • platform/mac/PowerObserverMac.h: Copied from Source/WebCore/platform/efl/SharedTimerEfl.cpp.
  • platform/mac/PowerObserverMac.mm: Renamed from Source/WebCore/platform/mac/SharedTimerMac.mm.

(WebCore::PowerObserver::PowerObserver):
(WebCore::PowerObserver::~PowerObserver):
(WebCore::PowerObserver::didReceiveSystemPowerNotification):

  • platform/win/SharedTimerWin.cpp:

(WebCore::removeSharedTimer):

Location:
trunk/Source/WebCore
Files:
1 added
1 deleted
7 edited
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r181668 r181671  
     12015-03-17  Chris Dumez  <cdumez@apple.com>
     2
     3        [Mac][iOS] setSharedTimerFireInterval() / stopSharedTimer() are expensive
     4        https://bugs.webkit.org/show_bug.cgi?id=142752
     5        <rdar://problem/20176731>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        setSharedTimerFireInterval() / stopSharedTimer() are expensive on Mac
     10        and iOS on pages using a lot of timers.
     11
     12        For example, on bing.com / iOS, ~15.4% of the CPU time is spent in
     13        setSharedTimerFireInterval() and ~14.7% of the CPU time is spent in
     14        stopSharedTimer(). The expensive calls are CFRunLoopAddTimer (11.4%),
     15        CFRunLoopTimerInvalidate (14.1%), CFRunLoopTimerCreate (3.3%).
     16
     17        The issue is that we keep creating, adding to run loop modes, and then
     18        destroying the sharedTimer for each firing event. This is very
     19        expensive. In such case, the CFRunLoopTimerRef documentation advises to
     20        """
     21        ... create a repeating timer with an initial firing time in the distant
     22        future (or the initial firing time) and a very large repeat interval—on
     23        the order of decades or more—and add it to all the necessary run loop
     24        modes. Then, when you know when the timer should fire next, you reset
     25        the firing time with CFRunLoopTimerSetNextFireDate, perhaps from the
     26        timer’s own callback function. This technique effectively produces a
     27        reusable, asynchronous timer.
     28        """ [1].
     29
     30        Doing so greatly decreases CPU time spend in:
     31        - setSharedTimerFireInterval(): 15.4% -> 4.6%
     32        - stopSharedTimer(): 14.6% -> 8.6%
     33
     34        Overall CPU time spent on bing.com in timerFired() goes down from
     35        ~61.2% to ~49.5%.
     36
     37        This patch also refactors the SharedTimer code to share as much as
     38        possible between Mac and iOS.
     39
     40        This patch is based in part on the following patch:
     41        http://trac.webkit.org/changeset/143210
     42
     43        [1] https://developer.apple.com/library/prerelease/ios/documentation/CoreFoundation/Reference/CFRunLoopTimerRef/index.html#//apple_ref/c/func/CFRunLoopTimerSetNextFireDate
     44
     45        * WebCore.xcodeproj/project.pbxproj:
     46        * platform/SharedTimer.h:
     47        (WebCore::SharedTimer::invalidate):
     48        (WebCore::MainThreadSharedTimer::setFiredFunction): Deleted.
     49        (WebCore::MainThreadSharedTimer::setFireInterval): Deleted.
     50        (WebCore::MainThreadSharedTimer::stop): Deleted.
     51        * platform/ThreadTimers.cpp:
     52        (WebCore::ThreadTimers::fireTimersInNestedEventLoop):
     53        * platform/cf/SharedTimerCF.mm: Added.
     54        (WebCore::applicationDidBecomeActive):
     55        (WebCore::setupPowerObserver):
     56        (WebCore::setSharedTimerFiredFunction):
     57        (WebCore::timerFired):
     58        (WebCore::restartSharedTimer):
     59        (WebCore::invalidateSharedTimer):
     60        (WebCore::setSharedTimerFireInterval):
     61        (WebCore::stopSharedTimer):
     62        * platform/efl/SharedTimerEfl.cpp:
     63        (WebCore::invalidateSharedTimer):
     64        * platform/gtk/SharedTimerGtk.cpp:
     65        (WebCore::invalidateSharedTimer):
     66        * platform/ios/SharedTimerIOS.mm: Removed.
     67        * platform/mac/PowerObserverMac.h: Copied from Source/WebCore/platform/efl/SharedTimerEfl.cpp.
     68        * platform/mac/PowerObserverMac.mm: Renamed from Source/WebCore/platform/mac/SharedTimerMac.mm.
     69        (WebCore::PowerObserver::PowerObserver):
     70        (WebCore::PowerObserver::~PowerObserver):
     71        (WebCore::PowerObserver::didReceiveSystemPowerNotification):
     72        * platform/win/SharedTimerWin.cpp:
     73        (WebCore::removeSharedTimer):
     74
    1752015-03-17  Tim Horton  <timothy_horton@apple.com>
    276
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r181616 r181671  
    16391639                46C83EFD1A9BBE2900A79A41 /* GeoNotifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46C83EFB1A9BBE2900A79A41 /* GeoNotifier.cpp */; };
    16401640                46C83EFE1A9BBE2900A79A41 /* GeoNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C83EFC1A9BBE2900A79A41 /* GeoNotifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1641                46D791141AB89A9B001B696B /* SharedTimerCF.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46D791131AB89A9B001B696B /* SharedTimerCF.mm */; };
     1642                46DBB6501AB8C96F00D9A813 /* PowerObserverMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DBB64E1AB8C96F00D9A813 /* PowerObserverMac.h */; };
     1643                46DBB6511AB8C96F00D9A813 /* PowerObserverMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46DBB64F1AB8C96F00D9A813 /* PowerObserverMac.mm */; };
    16411644                46FCB6181A70820E00C5A21E /* DiagnosticLoggingKeys.h in Headers */ = {isa = PBXBuildFile; fileRef = CD37B37515C1A7E1006DC898 /* DiagnosticLoggingKeys.h */; settings = {ATTRIBUTES = (Private, ); }; };
    16421645                490707E61219C04300D90E51 /* ANGLEWebKitBridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 490707E41219C04300D90E51 /* ANGLEWebKitBridge.cpp */; };
     
    33093312                93309E23099E64920056E581 /* WrapContentsInDummySpanCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93309DD4099E64910056E581 /* WrapContentsInDummySpanCommand.cpp */; };
    33103313                93309E24099E64920056E581 /* WrapContentsInDummySpanCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 93309DD5099E64910056E581 /* WrapContentsInDummySpanCommand.h */; };
    3311                 93309EA2099EB78C0056E581 /* SharedTimerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93309E9F099EB78C0056E581 /* SharedTimerMac.mm */; };
    33123314                93309EA3099EB78C0056E581 /* SharedTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 93309EA0099EB78C0056E581 /* SharedTimer.h */; };
    33133315                93309EA4099EB78C0056E581 /* Timer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93309EA1099EB78C0056E581 /* Timer.cpp */; };
     
    62356237                E45390430EAFD637003695C8 /* PlatformScreenIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390320EAFD637003695C8 /* PlatformScreenIOS.mm */; };
    62366238                E45390450EAFD637003695C8 /* ScrollViewIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390340EAFD637003695C8 /* ScrollViewIOS.mm */; };
    6237                 E45390460EAFD637003695C8 /* SharedTimerIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390350EAFD637003695C8 /* SharedTimerIOS.mm */; };
    62386239                E45390470EAFD637003695C8 /* SoundIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390360EAFD637003695C8 /* SoundIOS.mm */; };
    62396240                E45390490EAFD637003695C8 /* WebCoreSystemInterfaceIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390380EAFD637003695C8 /* WebCoreSystemInterfaceIOS.mm */; };
     
    87688769                46C83EFB1A9BBE2900A79A41 /* GeoNotifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GeoNotifier.cpp; sourceTree = "<group>"; };
    87698770                46C83EFC1A9BBE2900A79A41 /* GeoNotifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeoNotifier.h; sourceTree = "<group>"; };
     8771                46D791131AB89A9B001B696B /* SharedTimerCF.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SharedTimerCF.mm; sourceTree = "<group>"; };
     8772                46DBB64E1AB8C96F00D9A813 /* PowerObserverMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PowerObserverMac.h; sourceTree = "<group>"; };
     8773                46DBB64F1AB8C96F00D9A813 /* PowerObserverMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PowerObserverMac.mm; sourceTree = "<group>"; };
    87708774                490707E41219C04300D90E51 /* ANGLEWebKitBridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ANGLEWebKitBridge.cpp; sourceTree = "<group>"; };
    87718775                490707E51219C04300D90E51 /* ANGLEWebKitBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANGLEWebKitBridge.h; sourceTree = "<group>"; };
     
    1052010524                93309DD4099E64910056E581 /* WrapContentsInDummySpanCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WrapContentsInDummySpanCommand.cpp; sourceTree = "<group>"; };
    1052110525                93309DD5099E64910056E581 /* WrapContentsInDummySpanCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WrapContentsInDummySpanCommand.h; sourceTree = "<group>"; };
    10522                 93309E9F099EB78C0056E581 /* SharedTimerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SharedTimerMac.mm; sourceTree = "<group>"; };
    1052310526                93309EA0099EB78C0056E581 /* SharedTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharedTimer.h; sourceTree = "<group>"; };
    1052410527                93309EA1099EB78C0056E581 /* Timer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Timer.cpp; sourceTree = "<group>"; };
     
    1381413817                E45390320EAFD637003695C8 /* PlatformScreenIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PlatformScreenIOS.mm; path = ios/PlatformScreenIOS.mm; sourceTree = "<group>"; };
    1381513818                E45390340EAFD637003695C8 /* ScrollViewIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ScrollViewIOS.mm; path = ios/ScrollViewIOS.mm; sourceTree = "<group>"; };
    13816                 E45390350EAFD637003695C8 /* SharedTimerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SharedTimerIOS.mm; path = ios/SharedTimerIOS.mm; sourceTree = "<group>"; };
    1381713819                E45390360EAFD637003695C8 /* SoundIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SoundIOS.mm; path = ios/SoundIOS.mm; sourceTree = "<group>"; };
    1381813820                E45390380EAFD637003695C8 /* WebCoreSystemInterfaceIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebCoreSystemInterfaceIOS.mm; path = ios/WebCoreSystemInterfaceIOS.mm; sourceTree = "<group>"; };
     
    1520615208                                2D76BB801945632400CFD29A /* RunLoopObserver.h */,
    1520715209                                512DD8E20D91E2B4000F89EE /* SharedBufferCF.cpp */,
     15210                                46D791131AB89A9B001B696B /* SharedTimerCF.mm */,
    1520815211                                1A98956A0AA78F80005EF5EF /* URLCF.cpp */,
    1520915212                                5CBC8DAA1AAA302200E1C803 /* MediaAccessibilitySoftLink.cpp */,
     
    1666016663                                BC94D1070C274F88006BC617 /* PlatformScreenMac.mm */,
    1666116664                                29E4D8E016B0959800C84704 /* PlatformSpeechSynthesizerMac.mm */,
     16665                                46DBB64E1AB8C96F00D9A813 /* PowerObserverMac.h */,
     16666                                46DBB64F1AB8C96F00D9A813 /* PowerObserverMac.mm */,
    1666216667                                0081FEFE16B0A2B6008AAA7A /* PublicSuffixMac.mm */,
    1666316668                                BCAE1FA512939DB7004CB026 /* ScrollAnimatorMac.h */,
     
    1666916674                                077AF14218F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.mm */,
    1667016675                                1A4A95510B4EDCFF002D8C3C /* SharedBufferMac.mm */,
    16671                                 93309E9F099EB78C0056E581 /* SharedTimerMac.mm */,
    1667216676                                0A4844980CA44CB200B7BD48 /* SoftLinking.h */,
    1667316677                                4B3043C80AE0371D00A82647 /* SoundMac.mm */,
     
    1873018734                                BEA807C60F714A0300524199 /* SelectionRect.cpp */,
    1873118735                                BEA807C70F714A0300524199 /* SelectionRect.h */,
    18732                                 E45390350EAFD637003695C8 /* SharedTimerIOS.mm */,
    1873318736                                E45390360EAFD637003695C8 /* SoundIOS.mm */,
    1873418737                                4476531A133170990006B789 /* SSLKeyGeneratorIOS.cpp */,
     
    2683226835                                CDE83DB2183C44060031EAA3 /* VideoPlaybackQuality.h in Headers */,
    2683326836                                07C59B5717F4AC15000FBCBB /* VideoStreamTrack.h in Headers */,
     26837                                46DBB6501AB8C96F00D9A813 /* PowerObserverMac.h in Headers */,
    2683426838                                BE88E0DF1715D2A200658D98 /* VideoTrack.h in Headers */,
    2683526839                                BE88E0E21715D2A200658D98 /* VideoTrackList.h in Headers */,
     
    2796927973                                4B3043CC0AE0373B00A82647 /* Editor.cpp in Sources */,
    2797027974                                93A38B4B0D0E5808006872C2 /* EditorCommand.cpp in Sources */,
     27975                                46D791141AB89A9B001B696B /* SharedTimerCF.mm in Sources */,
    2797127976                                0760C17A1AA8FC7D009ED7B8 /* MediaPlaybackTargetMac.mm in Sources */,
    2797227977                                FED13D3A0CEA934600D89466 /* EditorIOS.mm in Sources */,
     
    2933629341                                A88DD4890B4629B000C02990 /* PathTraversalState.cpp in Sources */,
    2933729342                                A8FA6E5E0E4CFDED00D5CF49 /* Pattern.cpp in Sources */,
     29343                                46DBB6511AB8C96F00D9A813 /* PowerObserverMac.mm in Sources */,
    2933829344                                A80A38FE0E50CC8200A25EBC /* PatternCG.cpp in Sources */,
    2933929345                                B27535640B053814002CE64F /* PDFDocumentImage.cpp in Sources */,
     
    2969329699                                97B1F02E13B025CA00F5103F /* SharedBufferChunkReader.cpp in Sources */,
    2969429700                                1A4A95520B4EDCFF002D8C3C /* SharedBufferMac.mm in Sources */,
    29695                                 E45390460EAFD637003695C8 /* SharedTimerIOS.mm in Sources */,
    29696                                 93309EA2099EB78C0056E581 /* SharedTimerMac.mm in Sources */,
    2969729701                                B2C3DA640D006CD600EF6F26 /* Font.cpp in Sources */,
    2969829702                                163E88F7118A39D200ED9231 /* SimpleFontDataCoreText.cpp in Sources */,
  • trunk/Source/WebCore/platform/SharedTimer.h

    r165676 r181671  
    4545        virtual void setFireInterval(double) = 0;
    4646        virtual void stop() = 0;
     47
     48        virtual void invalidate() { }
    4749    };
    4850
     
    5355    void setSharedTimerFireInterval(double);
    5456    void stopSharedTimer();
     57    void invalidateSharedTimer();
    5558
    5659    // Implementation of SharedTimer for the main thread.
    57     class MainThreadSharedTimer : public SharedTimer {
     60    class MainThreadSharedTimer final : public SharedTimer {
    5861    public:
    59         virtual void setFiredFunction(void (*function)())
     62        void setFiredFunction(void (*function)()) override
    6063        {
    6164            setSharedTimerFiredFunction(function);
    6265        }
    6366       
    64         virtual void setFireInterval(double interval)
     67        void setFireInterval(double interval) override
    6568        {
    6669            setSharedTimerFireInterval(interval);
    6770        }
    6871       
    69         virtual void stop()
     72        void stop() override
    7073        {
    7174            stopSharedTimer();
     75        }
     76
     77        void invalidate() override
     78        {
     79            invalidateSharedTimer();
    7280        }
    7381    };
  • trunk/Source/WebCore/platform/ThreadTimers.cpp

    r165676 r181671  
    146146    // Reset the reentrancy guard so the timers can fire again.
    147147    m_firingTimers = false;
     148
     149    if (m_sharedTimer) {
     150        m_sharedTimer->invalidate();
     151        m_pendingSharedTimerFireTime = 0;
     152    }
     153
    148154    updateSharedTimer();
    149155}
  • trunk/Source/WebCore/platform/efl/SharedTimerEfl.cpp

    r165676 r181671  
    7575}
    7676
     77void invalidateSharedTimer()
     78{
    7779}
    7880
     81}
     82
  • trunk/Source/WebCore/platform/gtk/SharedTimerGtk.cpp

    r175245 r181671  
    5858}
    5959
     60void invalidateSharedTimer()
     61{
    6062}
     63
     64}
  • trunk/Source/WebCore/platform/mac/PowerObserverMac.h

    r181670 r181671  
    11/*
    2  * Copyright (C) 2008 Kenneth Rohde Christiansen
    3  *           (C) 2008 Afonso Rabelo Costa Jr.
    4  *           (C) 2009-2010 ProFUSION embedded systems
    5  *           (C) 2009-2010 Samsung Electronics
     2 * Copyright (C) 2006, 2010, 2015 Apple Inc. All rights reserved.
    63 *
    74 * Redistribution and use in source and binary forms, with or without
     
    2724 */
    2825
    29 #include "config.h"
    30 #include "SharedTimer.h"
     26#ifndef PowerObserverMac_h
     27#define PowerObserverMac_h
    3128
    32 #include <Ecore.h>
    33 #include <wtf/Assertions.h>
    34 #include <wtf/CurrentTime.h>
    35 #include <wtf/MainThread.h>
     29#import <IOKit/IOMessage.h>
     30#import <IOKit/pwr_mgt/IOPMLib.h>
     31#import <functional>
     32#import <wtf/Noncopyable.h>
    3633
    3734namespace WebCore {
    3835
    39 static Ecore_Timer *_sharedTimer = 0;
     36class PowerObserver {
     37    WTF_MAKE_NONCOPYABLE(PowerObserver);
    4038
    41 static void (*_timerFunction)();
     39public:
     40    PowerObserver(const std::function<void()>& powerOnHander);
     41    ~PowerObserver();
    4242
    43 void setSharedTimerFiredFunction(void (*func)())
    44 {
    45     _timerFunction = func;
    46 }
     43private:
     44    void didReceiveSystemPowerNotification(io_service_t, uint32_t messageType, void* messageArgument);
    4745
    48 static Eina_Bool timerEvent(void*)
    49 {
    50     _sharedTimer = 0;
    51     if (_timerFunction)
    52         _timerFunction();
     46    std::function<void()> m_powerOnHander;
     47    io_connect_t m_powerConnection;
     48    IONotificationPortRef m_notificationPort;
     49    io_object_t m_notifierReference;
     50    dispatch_queue_t m_dispatchQueue;
     51};
    5352
    54     return ECORE_CALLBACK_CANCEL;
    55 }
     53} // namespace WebCore
    5654
    57 void stopSharedTimer()
    58 {
    59     if (_sharedTimer) {
    60         ecore_timer_del(_sharedTimer);
    61         _sharedTimer = 0;
    62     }
    63 }
     55#endif // PowerObserverMac_h
    6456
    65 void addNewTimer(double interval)
    66 {
    67     stopSharedTimer();
    68 
    69     _sharedTimer = ecore_timer_loop_add(interval, timerEvent, 0);
    70 }
    71 
    72 void setSharedTimerFireInterval(double interval)
    73 {
    74     addNewTimer(interval);
    75 }
    76 
    77 }
    78 
  • trunk/Source/WebCore/platform/mac/PowerObserverMac.mm

    r181670 r181671  
    11/*
    2  * Copyright (C) 2006, 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2006, 2010, 2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    2626#import "config.h"
    27 #import "SharedTimer.h"
    2827
    29 #import <IOKit/IOMessage.h>
    30 #import <IOKit/pwr_mgt/IOPMLib.h>
    31 #import <stdio.h>
    32 #import <wtf/Assertions.h>
    33 #import <wtf/Noncopyable.h>
    34 #import <wtf/PassOwnPtr.h>
     28#if PLATFORM(MAC)
     29#import "PowerObserverMac.h"
    3530
    3631namespace WebCore {
    3732
    38 static CFRunLoopTimerRef sharedTimer;
    39 static void (*sharedTimerFiredFunction)();
    40 static void timerFired(CFRunLoopTimerRef, void*);
    41 
    42 class PowerObserver {
    43     WTF_MAKE_NONCOPYABLE(PowerObserver);
    44    
    45 public:
    46     PowerObserver();
    47     ~PowerObserver();
    48 
    49 private:
    50     void didReceiveSystemPowerNotification(io_service_t, uint32_t messageType, void* messageArgument);
    51 
    52     void restartSharedTimer();
    53 
    54     io_connect_t m_powerConnection;
    55     IONotificationPortRef m_notificationPort;
    56     io_object_t m_notifierReference;
    57     dispatch_queue_t m_dispatchQueue;
    58 };
    59 
    60 PowerObserver::PowerObserver()
    61     : m_powerConnection(0)
     33PowerObserver::PowerObserver(const std::function<void()>& powerOnHander)
     34    : m_powerOnHander(powerOnHander)
     35    , m_powerConnection(0)
    6236    , m_notificationPort(nullptr)
    6337    , m_notifierReference(0)
     
    9569    // We need to restart the timer on the main thread.
    9670    CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopCommonModes, ^() {
    97         restartSharedTimer();
     71        m_powerOnHander();
    9872    });
    9973}
    10074
    101 void PowerObserver::restartSharedTimer()
    102 {
    103     ASSERT(CFRunLoopGetCurrent() == CFRunLoopGetMain());
     75} // namespace WebCore
    10476
    105     if (!sharedTimer)
    106         return;
    107 
    108     stopSharedTimer();
    109     timerFired(0, 0);
    110 }
    111 
    112 static PowerObserver* powerObserver;
    113 
    114 void setSharedTimerFiredFunction(void (*f)())
    115 {
    116     ASSERT(!sharedTimerFiredFunction || sharedTimerFiredFunction == f);
    117 
    118     sharedTimerFiredFunction = f;
    119 }
    120 
    121 static void timerFired(CFRunLoopTimerRef, void*)
    122 {
    123     @autoreleasepool {
    124         sharedTimerFiredFunction();
    125     }
    126 }
    127 
    128 void setSharedTimerFireInterval(double interval)
    129 {
    130     ASSERT(sharedTimerFiredFunction);
    131 
    132     if (sharedTimer) {
    133         CFRunLoopTimerInvalidate(sharedTimer);
    134         CFRelease(sharedTimer);
    135     }
    136 
    137     CFAbsoluteTime fireDate = CFAbsoluteTimeGetCurrent() + interval;
    138     sharedTimer = CFRunLoopTimerCreate(0, fireDate, 0, 0, 0, timerFired, 0);
    139     CFRunLoopAddTimer(CFRunLoopGetCurrent(), sharedTimer, kCFRunLoopCommonModes);
    140    
    141     if (!powerObserver)
    142         powerObserver = std::make_unique<PowerObserver>().release();
    143 }
    144 
    145 void stopSharedTimer()
    146 {
    147     if (sharedTimer) {
    148         CFRunLoopTimerInvalidate(sharedTimer);
    149         CFRelease(sharedTimer);
    150         sharedTimer = 0;
    151     }
    152 }
    153 
    154 } // namespace WebCore
     77#endif
  • trunk/Source/WebCore/platform/win/SharedTimerWin.cpp

    r177991 r181671  
    199199}
    200200
    201 }
     201void invalidateSharedTimer()
     202{
     203}
     204
     205}
Note: See TracChangeset for help on using the changeset viewer.