Changeset 181671 in webkit
- Timestamp:
- Mar 17, 2015, 4:42:46 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 1 added
- 1 deleted
- 7 edited
- 1 copied
- 1 moved
-
ChangeLog (modified) (1 diff)
-
WebCore.xcodeproj/project.pbxproj (modified) (14 diffs)
-
platform/SharedTimer.h (modified) (2 diffs)
-
platform/ThreadTimers.cpp (modified) (1 diff)
-
platform/cf/SharedTimerCF.mm (added)
-
platform/efl/SharedTimerEfl.cpp (modified) (1 diff)
-
platform/gtk/SharedTimerGtk.cpp (modified) (1 diff)
-
platform/ios/SharedTimerIOS.mm (deleted)
-
platform/mac/PowerObserverMac.h (copied) (copied from trunk/Source/WebCore/platform/efl/SharedTimerEfl.cpp ) (2 diffs)
-
platform/mac/PowerObserverMac.mm (moved) (moved from trunk/Source/WebCore/platform/mac/SharedTimerMac.mm ) (3 diffs)
-
platform/win/SharedTimerWin.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r181668 r181671 1 2015-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 1 75 2015-03-17 Tim Horton <timothy_horton@apple.com> 2 76 -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r181616 r181671 1639 1639 46C83EFD1A9BBE2900A79A41 /* GeoNotifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46C83EFB1A9BBE2900A79A41 /* GeoNotifier.cpp */; }; 1640 1640 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 */; }; 1641 1644 46FCB6181A70820E00C5A21E /* DiagnosticLoggingKeys.h in Headers */ = {isa = PBXBuildFile; fileRef = CD37B37515C1A7E1006DC898 /* DiagnosticLoggingKeys.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1642 1645 490707E61219C04300D90E51 /* ANGLEWebKitBridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 490707E41219C04300D90E51 /* ANGLEWebKitBridge.cpp */; }; … … 3309 3312 93309E23099E64920056E581 /* WrapContentsInDummySpanCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93309DD4099E64910056E581 /* WrapContentsInDummySpanCommand.cpp */; }; 3310 3313 93309E24099E64920056E581 /* WrapContentsInDummySpanCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 93309DD5099E64910056E581 /* WrapContentsInDummySpanCommand.h */; }; 3311 93309EA2099EB78C0056E581 /* SharedTimerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93309E9F099EB78C0056E581 /* SharedTimerMac.mm */; };3312 3314 93309EA3099EB78C0056E581 /* SharedTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 93309EA0099EB78C0056E581 /* SharedTimer.h */; }; 3313 3315 93309EA4099EB78C0056E581 /* Timer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93309EA1099EB78C0056E581 /* Timer.cpp */; }; … … 6235 6237 E45390430EAFD637003695C8 /* PlatformScreenIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390320EAFD637003695C8 /* PlatformScreenIOS.mm */; }; 6236 6238 E45390450EAFD637003695C8 /* ScrollViewIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390340EAFD637003695C8 /* ScrollViewIOS.mm */; }; 6237 E45390460EAFD637003695C8 /* SharedTimerIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390350EAFD637003695C8 /* SharedTimerIOS.mm */; };6238 6239 E45390470EAFD637003695C8 /* SoundIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390360EAFD637003695C8 /* SoundIOS.mm */; }; 6239 6240 E45390490EAFD637003695C8 /* WebCoreSystemInterfaceIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390380EAFD637003695C8 /* WebCoreSystemInterfaceIOS.mm */; }; … … 8768 8769 46C83EFB1A9BBE2900A79A41 /* GeoNotifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GeoNotifier.cpp; sourceTree = "<group>"; }; 8769 8770 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>"; }; 8770 8774 490707E41219C04300D90E51 /* ANGLEWebKitBridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ANGLEWebKitBridge.cpp; sourceTree = "<group>"; }; 8771 8775 490707E51219C04300D90E51 /* ANGLEWebKitBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANGLEWebKitBridge.h; sourceTree = "<group>"; }; … … 10520 10524 93309DD4099E64910056E581 /* WrapContentsInDummySpanCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WrapContentsInDummySpanCommand.cpp; sourceTree = "<group>"; }; 10521 10525 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>"; };10523 10526 93309EA0099EB78C0056E581 /* SharedTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharedTimer.h; sourceTree = "<group>"; }; 10524 10527 93309EA1099EB78C0056E581 /* Timer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Timer.cpp; sourceTree = "<group>"; }; … … 13814 13817 E45390320EAFD637003695C8 /* PlatformScreenIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PlatformScreenIOS.mm; path = ios/PlatformScreenIOS.mm; sourceTree = "<group>"; }; 13815 13818 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>"; };13817 13819 E45390360EAFD637003695C8 /* SoundIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SoundIOS.mm; path = ios/SoundIOS.mm; sourceTree = "<group>"; }; 13818 13820 E45390380EAFD637003695C8 /* WebCoreSystemInterfaceIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebCoreSystemInterfaceIOS.mm; path = ios/WebCoreSystemInterfaceIOS.mm; sourceTree = "<group>"; }; … … 15206 15208 2D76BB801945632400CFD29A /* RunLoopObserver.h */, 15207 15209 512DD8E20D91E2B4000F89EE /* SharedBufferCF.cpp */, 15210 46D791131AB89A9B001B696B /* SharedTimerCF.mm */, 15208 15211 1A98956A0AA78F80005EF5EF /* URLCF.cpp */, 15209 15212 5CBC8DAA1AAA302200E1C803 /* MediaAccessibilitySoftLink.cpp */, … … 16660 16663 BC94D1070C274F88006BC617 /* PlatformScreenMac.mm */, 16661 16664 29E4D8E016B0959800C84704 /* PlatformSpeechSynthesizerMac.mm */, 16665 46DBB64E1AB8C96F00D9A813 /* PowerObserverMac.h */, 16666 46DBB64F1AB8C96F00D9A813 /* PowerObserverMac.mm */, 16662 16667 0081FEFE16B0A2B6008AAA7A /* PublicSuffixMac.mm */, 16663 16668 BCAE1FA512939DB7004CB026 /* ScrollAnimatorMac.h */, … … 16669 16674 077AF14218F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.mm */, 16670 16675 1A4A95510B4EDCFF002D8C3C /* SharedBufferMac.mm */, 16671 93309E9F099EB78C0056E581 /* SharedTimerMac.mm */,16672 16676 0A4844980CA44CB200B7BD48 /* SoftLinking.h */, 16673 16677 4B3043C80AE0371D00A82647 /* SoundMac.mm */, … … 18730 18734 BEA807C60F714A0300524199 /* SelectionRect.cpp */, 18731 18735 BEA807C70F714A0300524199 /* SelectionRect.h */, 18732 E45390350EAFD637003695C8 /* SharedTimerIOS.mm */,18733 18736 E45390360EAFD637003695C8 /* SoundIOS.mm */, 18734 18737 4476531A133170990006B789 /* SSLKeyGeneratorIOS.cpp */, … … 26832 26835 CDE83DB2183C44060031EAA3 /* VideoPlaybackQuality.h in Headers */, 26833 26836 07C59B5717F4AC15000FBCBB /* VideoStreamTrack.h in Headers */, 26837 46DBB6501AB8C96F00D9A813 /* PowerObserverMac.h in Headers */, 26834 26838 BE88E0DF1715D2A200658D98 /* VideoTrack.h in Headers */, 26835 26839 BE88E0E21715D2A200658D98 /* VideoTrackList.h in Headers */, … … 27969 27973 4B3043CC0AE0373B00A82647 /* Editor.cpp in Sources */, 27970 27974 93A38B4B0D0E5808006872C2 /* EditorCommand.cpp in Sources */, 27975 46D791141AB89A9B001B696B /* SharedTimerCF.mm in Sources */, 27971 27976 0760C17A1AA8FC7D009ED7B8 /* MediaPlaybackTargetMac.mm in Sources */, 27972 27977 FED13D3A0CEA934600D89466 /* EditorIOS.mm in Sources */, … … 29336 29341 A88DD4890B4629B000C02990 /* PathTraversalState.cpp in Sources */, 29337 29342 A8FA6E5E0E4CFDED00D5CF49 /* Pattern.cpp in Sources */, 29343 46DBB6511AB8C96F00D9A813 /* PowerObserverMac.mm in Sources */, 29338 29344 A80A38FE0E50CC8200A25EBC /* PatternCG.cpp in Sources */, 29339 29345 B27535640B053814002CE64F /* PDFDocumentImage.cpp in Sources */, … … 29693 29699 97B1F02E13B025CA00F5103F /* SharedBufferChunkReader.cpp in Sources */, 29694 29700 1A4A95520B4EDCFF002D8C3C /* SharedBufferMac.mm in Sources */, 29695 E45390460EAFD637003695C8 /* SharedTimerIOS.mm in Sources */,29696 93309EA2099EB78C0056E581 /* SharedTimerMac.mm in Sources */,29697 29701 B2C3DA640D006CD600EF6F26 /* Font.cpp in Sources */, 29698 29702 163E88F7118A39D200ED9231 /* SimpleFontDataCoreText.cpp in Sources */, -
trunk/Source/WebCore/platform/SharedTimer.h
r165676 r181671 45 45 virtual void setFireInterval(double) = 0; 46 46 virtual void stop() = 0; 47 48 virtual void invalidate() { } 47 49 }; 48 50 … … 53 55 void setSharedTimerFireInterval(double); 54 56 void stopSharedTimer(); 57 void invalidateSharedTimer(); 55 58 56 59 // Implementation of SharedTimer for the main thread. 57 class MainThreadSharedTimer : public SharedTimer {60 class MainThreadSharedTimer final : public SharedTimer { 58 61 public: 59 v irtual void setFiredFunction(void (*function)())62 void setFiredFunction(void (*function)()) override 60 63 { 61 64 setSharedTimerFiredFunction(function); 62 65 } 63 66 64 v irtual void setFireInterval(double interval)67 void setFireInterval(double interval) override 65 68 { 66 69 setSharedTimerFireInterval(interval); 67 70 } 68 71 69 v irtual void stop()72 void stop() override 70 73 { 71 74 stopSharedTimer(); 75 } 76 77 void invalidate() override 78 { 79 invalidateSharedTimer(); 72 80 } 73 81 }; -
trunk/Source/WebCore/platform/ThreadTimers.cpp
r165676 r181671 146 146 // Reset the reentrancy guard so the timers can fire again. 147 147 m_firingTimers = false; 148 149 if (m_sharedTimer) { 150 m_sharedTimer->invalidate(); 151 m_pendingSharedTimerFireTime = 0; 152 } 153 148 154 updateSharedTimer(); 149 155 } -
trunk/Source/WebCore/platform/efl/SharedTimerEfl.cpp
r165676 r181671 75 75 } 76 76 77 void invalidateSharedTimer() 78 { 77 79 } 78 80 81 } 82 -
trunk/Source/WebCore/platform/gtk/SharedTimerGtk.cpp
r175245 r181671 58 58 } 59 59 60 void invalidateSharedTimer() 61 { 60 62 } 63 64 } -
trunk/Source/WebCore/platform/mac/PowerObserverMac.h
r181670 r181671 1 1 /* 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. 6 3 * 7 4 * Redistribution and use in source and binary forms, with or without … … 27 24 */ 28 25 29 #i nclude "config.h"30 # include "SharedTimer.h"26 #ifndef PowerObserverMac_h 27 #define PowerObserverMac_h 31 28 32 #i nclude <Ecore.h>33 #i nclude <wtf/Assertions.h>34 #i nclude <wtf/CurrentTime.h>35 #i nclude <wtf/MainThread.h>29 #import <IOKit/IOMessage.h> 30 #import <IOKit/pwr_mgt/IOPMLib.h> 31 #import <functional> 32 #import <wtf/Noncopyable.h> 36 33 37 34 namespace WebCore { 38 35 39 static Ecore_Timer *_sharedTimer = 0; 36 class PowerObserver { 37 WTF_MAKE_NONCOPYABLE(PowerObserver); 40 38 41 static void (*_timerFunction)(); 39 public: 40 PowerObserver(const std::function<void()>& powerOnHander); 41 ~PowerObserver(); 42 42 43 void setSharedTimerFiredFunction(void (*func)()) 44 { 45 _timerFunction = func; 46 } 43 private: 44 void didReceiveSystemPowerNotification(io_service_t, uint32_t messageType, void* messageArgument); 47 45 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 }; 53 52 54 return ECORE_CALLBACK_CANCEL; 55 } 53 } // namespace WebCore 56 54 57 void stopSharedTimer() 58 { 59 if (_sharedTimer) { 60 ecore_timer_del(_sharedTimer); 61 _sharedTimer = 0; 62 } 63 } 55 #endif // PowerObserverMac_h 64 56 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 1 1 /* 2 * Copyright (C) 2006, 2010 Apple Inc. All rights reserved.2 * Copyright (C) 2006, 2010, 2015 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (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. 24 24 */ 25 25 26 26 #import "config.h" 27 #import "SharedTimer.h"28 27 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" 35 30 36 31 namespace WebCore { 37 32 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) 33 PowerObserver::PowerObserver(const std::function<void()>& powerOnHander) 34 : m_powerOnHander(powerOnHander) 35 , m_powerConnection(0) 62 36 , m_notificationPort(nullptr) 63 37 , m_notifierReference(0) … … 95 69 // We need to restart the timer on the main thread. 96 70 CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopCommonModes, ^() { 97 restartSharedTimer();71 m_powerOnHander(); 98 72 }); 99 73 } 100 74 101 void PowerObserver::restartSharedTimer() 102 { 103 ASSERT(CFRunLoopGetCurrent() == CFRunLoopGetMain()); 75 } // namespace WebCore 104 76 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 199 199 } 200 200 201 } 201 void invalidateSharedTimer() 202 { 203 } 204 205 }
Note:
See TracChangeset
for help on using the changeset viewer.