Diff
Modified: trunk/Source/WebCore/ChangeLog (181670 => 181671)
--- trunk/Source/WebCore/ChangeLog 2015-03-17 23:06:37 UTC (rev 181670)
+++ trunk/Source/WebCore/ChangeLog 2015-03-17 23:42:46 UTC (rev 181671)
@@ -1,3 +1,77 @@
+2015-03-17 Chris Dumez <[email protected]>
+
+ [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):
+
2015-03-17 Tim Horton <[email protected]>
Cannot invoke action menus anymore
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (181670 => 181671)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2015-03-17 23:06:37 UTC (rev 181670)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2015-03-17 23:42:46 UTC (rev 181671)
@@ -1638,6 +1638,9 @@
4689F1AF1267BAE100E8D380 /* FileMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = 4689F1AE1267BAE100E8D380 /* FileMetadata.h */; };
46C83EFD1A9BBE2900A79A41 /* GeoNotifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 46C83EFB1A9BBE2900A79A41 /* GeoNotifier.cpp */; };
46C83EFE1A9BBE2900A79A41 /* GeoNotifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 46C83EFC1A9BBE2900A79A41 /* GeoNotifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ 46D791141AB89A9B001B696B /* SharedTimerCF.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46D791131AB89A9B001B696B /* SharedTimerCF.mm */; };
+ 46DBB6501AB8C96F00D9A813 /* PowerObserverMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 46DBB64E1AB8C96F00D9A813 /* PowerObserverMac.h */; };
+ 46DBB6511AB8C96F00D9A813 /* PowerObserverMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 46DBB64F1AB8C96F00D9A813 /* PowerObserverMac.mm */; };
46FCB6181A70820E00C5A21E /* DiagnosticLoggingKeys.h in Headers */ = {isa = PBXBuildFile; fileRef = CD37B37515C1A7E1006DC898 /* DiagnosticLoggingKeys.h */; settings = {ATTRIBUTES = (Private, ); }; };
490707E61219C04300D90E51 /* ANGLEWebKitBridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 490707E41219C04300D90E51 /* ANGLEWebKitBridge.cpp */; };
490707E71219C04300D90E51 /* ANGLEWebKitBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 490707E51219C04300D90E51 /* ANGLEWebKitBridge.h */; };
@@ -3308,7 +3311,6 @@
93309E20099E64920056E581 /* VisiblePosition.h in Headers */ = {isa = PBXBuildFile; fileRef = 93309DD1099E64910056E581 /* VisiblePosition.h */; settings = {ATTRIBUTES = (Private, ); }; };
93309E23099E64920056E581 /* WrapContentsInDummySpanCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93309DD4099E64910056E581 /* WrapContentsInDummySpanCommand.cpp */; };
93309E24099E64920056E581 /* WrapContentsInDummySpanCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 93309DD5099E64910056E581 /* WrapContentsInDummySpanCommand.h */; };
- 93309EA2099EB78C0056E581 /* SharedTimerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93309E9F099EB78C0056E581 /* SharedTimerMac.mm */; };
93309EA3099EB78C0056E581 /* SharedTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 93309EA0099EB78C0056E581 /* SharedTimer.h */; };
93309EA4099EB78C0056E581 /* Timer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93309EA1099EB78C0056E581 /* Timer.cpp */; };
93354A3C0B24F8C9003F6DEA /* UIEventWithKeyState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93354A3B0B24F8C9003F6DEA /* UIEventWithKeyState.cpp */; };
@@ -6234,7 +6236,6 @@
E453901E0EAFCACA003695C8 /* PasteboardIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390190EAFCACA003695C8 /* PasteboardIOS.mm */; };
E45390430EAFD637003695C8 /* PlatformScreenIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390320EAFD637003695C8 /* PlatformScreenIOS.mm */; };
E45390450EAFD637003695C8 /* ScrollViewIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390340EAFD637003695C8 /* ScrollViewIOS.mm */; };
- E45390460EAFD637003695C8 /* SharedTimerIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390350EAFD637003695C8 /* SharedTimerIOS.mm */; };
E45390470EAFD637003695C8 /* SoundIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390360EAFD637003695C8 /* SoundIOS.mm */; };
E45390490EAFD637003695C8 /* WebCoreSystemInterfaceIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E45390380EAFD637003695C8 /* WebCoreSystemInterfaceIOS.mm */; };
E453904D0EAFD637003695C8 /* WidgetIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = E453903C0EAFD637003695C8 /* WidgetIOS.mm */; };
@@ -8767,6 +8768,9 @@
4689F1AE1267BAE100E8D380 /* FileMetadata.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileMetadata.h; path = platform/FileMetadata.h; sourceTree = "<group>"; };
46C83EFB1A9BBE2900A79A41 /* GeoNotifier.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GeoNotifier.cpp; sourceTree = "<group>"; };
46C83EFC1A9BBE2900A79A41 /* GeoNotifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GeoNotifier.h; sourceTree = "<group>"; };
+ 46D791131AB89A9B001B696B /* SharedTimerCF.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SharedTimerCF.mm; sourceTree = "<group>"; };
+ 46DBB64E1AB8C96F00D9A813 /* PowerObserverMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PowerObserverMac.h; sourceTree = "<group>"; };
+ 46DBB64F1AB8C96F00D9A813 /* PowerObserverMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PowerObserverMac.mm; sourceTree = "<group>"; };
490707E41219C04300D90E51 /* ANGLEWebKitBridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ANGLEWebKitBridge.cpp; sourceTree = "<group>"; };
490707E51219C04300D90E51 /* ANGLEWebKitBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANGLEWebKitBridge.h; sourceTree = "<group>"; };
49291E4A134172C800E753DE /* ImageRenderingMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ImageRenderingMode.h; sourceTree = "<group>"; };
@@ -10519,7 +10523,6 @@
93309DD1099E64910056E581 /* VisiblePosition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VisiblePosition.h; sourceTree = "<group>"; };
93309DD4099E64910056E581 /* WrapContentsInDummySpanCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WrapContentsInDummySpanCommand.cpp; sourceTree = "<group>"; };
93309DD5099E64910056E581 /* WrapContentsInDummySpanCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WrapContentsInDummySpanCommand.h; sourceTree = "<group>"; };
- 93309E9F099EB78C0056E581 /* SharedTimerMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SharedTimerMac.mm; sourceTree = "<group>"; };
93309EA0099EB78C0056E581 /* SharedTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharedTimer.h; sourceTree = "<group>"; };
93309EA1099EB78C0056E581 /* Timer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Timer.cpp; sourceTree = "<group>"; };
9332AB3D16515D7700D827EC /* GraphicsContext3DNEON.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsContext3DNEON.h; sourceTree = "<group>"; };
@@ -13813,7 +13816,6 @@
E45390190EAFCACA003695C8 /* PasteboardIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PasteboardIOS.mm; path = ios/PasteboardIOS.mm; sourceTree = "<group>"; };
E45390320EAFD637003695C8 /* PlatformScreenIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = PlatformScreenIOS.mm; path = ios/PlatformScreenIOS.mm; sourceTree = "<group>"; };
E45390340EAFD637003695C8 /* ScrollViewIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = ScrollViewIOS.mm; path = ios/ScrollViewIOS.mm; sourceTree = "<group>"; };
- E45390350EAFD637003695C8 /* SharedTimerIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SharedTimerIOS.mm; path = ios/SharedTimerIOS.mm; sourceTree = "<group>"; };
E45390360EAFD637003695C8 /* SoundIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SoundIOS.mm; path = ios/SoundIOS.mm; sourceTree = "<group>"; };
E45390380EAFD637003695C8 /* WebCoreSystemInterfaceIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebCoreSystemInterfaceIOS.mm; path = ios/WebCoreSystemInterfaceIOS.mm; sourceTree = "<group>"; };
E453903C0EAFD637003695C8 /* WidgetIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WidgetIOS.mm; path = ios/WidgetIOS.mm; sourceTree = "<group>"; };
@@ -15205,6 +15207,7 @@
2D76BB8319456F8100CFD29A /* RunLoopObserver.cpp */,
2D76BB801945632400CFD29A /* RunLoopObserver.h */,
512DD8E20D91E2B4000F89EE /* SharedBufferCF.cpp */,
+ 46D791131AB89A9B001B696B /* SharedTimerCF.mm */,
1A98956A0AA78F80005EF5EF /* URLCF.cpp */,
5CBC8DAA1AAA302200E1C803 /* MediaAccessibilitySoftLink.cpp */,
5CBC8DAB1AAA302200E1C803 /* MediaAccessibilitySoftLink.h */,
@@ -16659,6 +16662,8 @@
C5F765BA14E1ECF4006C899B /* PlatformPasteboardMac.mm */,
BC94D1070C274F88006BC617 /* PlatformScreenMac.mm */,
29E4D8E016B0959800C84704 /* PlatformSpeechSynthesizerMac.mm */,
+ 46DBB64E1AB8C96F00D9A813 /* PowerObserverMac.h */,
+ 46DBB64F1AB8C96F00D9A813 /* PowerObserverMac.mm */,
0081FEFE16B0A2B6008AAA7A /* PublicSuffixMac.mm */,
BCAE1FA512939DB7004CB026 /* ScrollAnimatorMac.h */,
BC51156D12B1749C00C96754 /* ScrollAnimatorMac.mm */,
@@ -16668,7 +16673,6 @@
077AF14118F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.h */,
077AF14218F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.mm */,
1A4A95510B4EDCFF002D8C3C /* SharedBufferMac.mm */,
- 93309E9F099EB78C0056E581 /* SharedTimerMac.mm */,
0A4844980CA44CB200B7BD48 /* SoftLinking.h */,
4B3043C80AE0371D00A82647 /* SoundMac.mm */,
84B2B24F056BF15F00D2B771 /* SSLKeyGeneratorMac.cpp */,
@@ -18729,7 +18733,6 @@
E45390340EAFD637003695C8 /* ScrollViewIOS.mm */,
BEA807C60F714A0300524199 /* SelectionRect.cpp */,
BEA807C70F714A0300524199 /* SelectionRect.h */,
- E45390350EAFD637003695C8 /* SharedTimerIOS.mm */,
E45390360EAFD637003695C8 /* SoundIOS.mm */,
4476531A133170990006B789 /* SSLKeyGeneratorIOS.cpp */,
0F03C0731884695E00A5F8CA /* SystemMemory.h */,
@@ -26831,6 +26834,7 @@
BCA257151293C010007A263D /* VerticalPositionCache.h in Headers */,
CDE83DB2183C44060031EAA3 /* VideoPlaybackQuality.h in Headers */,
07C59B5717F4AC15000FBCBB /* VideoStreamTrack.h in Headers */,
+ 46DBB6501AB8C96F00D9A813 /* PowerObserverMac.h in Headers */,
BE88E0DF1715D2A200658D98 /* VideoTrack.h in Headers */,
BE88E0E21715D2A200658D98 /* VideoTrackList.h in Headers */,
CD8B5A46180DFF4E008B8E65 /* VideoTrackMediaSource.h in Headers */,
@@ -27968,6 +27972,7 @@
9BAB6C6D12550631001626D4 /* EditingStyle.cpp in Sources */,
4B3043CC0AE0373B00A82647 /* Editor.cpp in Sources */,
93A38B4B0D0E5808006872C2 /* EditorCommand.cpp in Sources */,
+ 46D791141AB89A9B001B696B /* SharedTimerCF.mm in Sources */,
0760C17A1AA8FC7D009ED7B8 /* MediaPlaybackTargetMac.mm in Sources */,
FED13D3A0CEA934600D89466 /* EditorIOS.mm in Sources */,
ED501DC60B249F2900AE18D9 /* EditorMac.mm in Sources */,
@@ -29335,6 +29340,7 @@
B27535630B053814002CE64F /* PathCG.cpp in Sources */,
A88DD4890B4629B000C02990 /* PathTraversalState.cpp in Sources */,
A8FA6E5E0E4CFDED00D5CF49 /* Pattern.cpp in Sources */,
+ 46DBB6511AB8C96F00D9A813 /* PowerObserverMac.mm in Sources */,
A80A38FE0E50CC8200A25EBC /* PatternCG.cpp in Sources */,
B27535640B053814002CE64F /* PDFDocumentImage.cpp in Sources */,
2D6E468417D660F500ECF8BB /* PDFDocumentImageMac.mm in Sources */,
@@ -29692,8 +29698,6 @@
512DD8E30D91E2B4000F89EE /* SharedBufferCF.cpp in Sources */,
97B1F02E13B025CA00F5103F /* SharedBufferChunkReader.cpp in Sources */,
1A4A95520B4EDCFF002D8C3C /* SharedBufferMac.mm in Sources */,
- E45390460EAFD637003695C8 /* SharedTimerIOS.mm in Sources */,
- 93309EA2099EB78C0056E581 /* SharedTimerMac.mm in Sources */,
B2C3DA640D006CD600EF6F26 /* Font.cpp in Sources */,
163E88F7118A39D200ED9231 /* SimpleFontDataCoreText.cpp in Sources */,
E48944A2180B57D800F165D8 /* SimpleLineLayout.cpp in Sources */,
Modified: trunk/Source/WebCore/platform/SharedTimer.h (181670 => 181671)
--- trunk/Source/WebCore/platform/SharedTimer.h 2015-03-17 23:06:37 UTC (rev 181670)
+++ trunk/Source/WebCore/platform/SharedTimer.h 2015-03-17 23:42:46 UTC (rev 181671)
@@ -44,6 +44,8 @@
// The fire interval is in seconds relative to the current monotonic clock time.
virtual void setFireInterval(double) = 0;
virtual void stop() = 0;
+
+ virtual void invalidate() { }
};
@@ -52,24 +54,30 @@
void setSharedTimerFiredFunction(void (*)());
void setSharedTimerFireInterval(double);
void stopSharedTimer();
+ void invalidateSharedTimer();
// Implementation of SharedTimer for the main thread.
- class MainThreadSharedTimer : public SharedTimer {
+ class MainThreadSharedTimer final : public SharedTimer {
public:
- virtual void setFiredFunction(void (*function)())
+ void setFiredFunction(void (*function)()) override
{
setSharedTimerFiredFunction(function);
}
- virtual void setFireInterval(double interval)
+ void setFireInterval(double interval) override
{
setSharedTimerFireInterval(interval);
}
- virtual void stop()
+ void stop() override
{
stopSharedTimer();
}
+
+ void invalidate() override
+ {
+ invalidateSharedTimer();
+ }
};
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/ThreadTimers.cpp (181670 => 181671)
--- trunk/Source/WebCore/platform/ThreadTimers.cpp 2015-03-17 23:06:37 UTC (rev 181670)
+++ trunk/Source/WebCore/platform/ThreadTimers.cpp 2015-03-17 23:42:46 UTC (rev 181671)
@@ -145,6 +145,12 @@
{
// Reset the reentrancy guard so the timers can fire again.
m_firingTimers = false;
+
+ if (m_sharedTimer) {
+ m_sharedTimer->invalidate();
+ m_pendingSharedTimerFireTime = 0;
+ }
+
updateSharedTimer();
}
Added: trunk/Source/WebCore/platform/cf/SharedTimerCF.mm (0 => 181671)
--- trunk/Source/WebCore/platform/cf/SharedTimerCF.mm (rev 0)
+++ trunk/Source/WebCore/platform/cf/SharedTimerCF.mm 2015-03-17 23:42:46 UTC (rev 181671)
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2006, 2010, 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "SharedTimer.h"
+
+#if PLATFORM(MAC)
+#import "PowerObserverMac.h"
+#elif PLATFORM(IOS)
+#import "WebCoreThreadRun.h"
+#endif
+
+namespace WebCore {
+
+static CFRunLoopTimerRef sharedTimer;
+static void (*sharedTimerFiredFunction)();
+static void timerFired(CFRunLoopTimerRef, void*);
+static void restartSharedTimer();
+
+static const CFTimeInterval kCFTimeIntervalDistantFuture = std::numeric_limits<CFTimeInterval>::max();
+
+#if PLATFORM(IOS)
+static void applicationDidBecomeActive(CFNotificationCenterRef, void*, CFStringRef, const void*, CFDictionaryRef)
+{
+ WebThreadRun(^{
+ restartSharedTimer();
+ });
+}
+#endif
+
+static void setupPowerObserver()
+{
+#if PLATFORM(MAC)
+ static PowerObserver* powerObserver;
+ if (!powerObserver)
+ powerObserver = std::make_unique<PowerObserver>(restartSharedTimer).release();
+#elif PLATFORM(IOS)
+ static bool registeredForApplicationNotification = false;
+ if (!registeredForApplicationNotification) {
+ registeredForApplicationNotification = true;
+ CFNotificationCenterRef notificationCenter = CFNotificationCenterGetLocalCenter();
+ CFNotificationCenterAddObserver(notificationCenter, 0, applicationDidBecomeActive, CFSTR("UIApplicationDidBecomeActiveNotification"), NULL, CFNotificationSuspensionBehaviorCoalesce);
+ }
+#endif
+}
+
+void setSharedTimerFiredFunction(void (*f)())
+{
+ ASSERT(!sharedTimerFiredFunction || sharedTimerFiredFunction == f);
+
+ sharedTimerFiredFunction = f;
+}
+
+static void timerFired(CFRunLoopTimerRef, void*)
+{
+ @autoreleasepool {
+ sharedTimerFiredFunction();
+ }
+}
+
+static void restartSharedTimer()
+{
+ if (!sharedTimer)
+ return;
+
+ stopSharedTimer();
+ timerFired(0, 0);
+}
+
+void invalidateSharedTimer()
+{
+ if (!sharedTimer)
+ return;
+
+ CFRunLoopTimerInvalidate(sharedTimer);
+ CFRelease(sharedTimer);
+ sharedTimer = nullptr;
+}
+
+void setSharedTimerFireInterval(double interval)
+{
+ ASSERT(sharedTimerFiredFunction);
+
+ CFAbsoluteTime fireDate = CFAbsoluteTimeGetCurrent() + interval;
+ if (!sharedTimer) {
+ sharedTimer = CFRunLoopTimerCreate(nullptr, fireDate, kCFTimeIntervalDistantFuture, 0, 0, timerFired, nullptr);
+ CFRunLoopAddTimer(CFRunLoopGetCurrent(), sharedTimer, kCFRunLoopCommonModes);
+
+ setupPowerObserver();
+
+ return;
+ }
+
+ CFRunLoopTimerSetNextFireDate(sharedTimer, fireDate);
+}
+
+void stopSharedTimer()
+{
+ if (!sharedTimer)
+ return;
+
+ CFRunLoopTimerSetNextFireDate(sharedTimer, kCFTimeIntervalDistantFuture);
+}
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/platform/efl/SharedTimerEfl.cpp (181670 => 181671)
--- trunk/Source/WebCore/platform/efl/SharedTimerEfl.cpp 2015-03-17 23:06:37 UTC (rev 181670)
+++ trunk/Source/WebCore/platform/efl/SharedTimerEfl.cpp 2015-03-17 23:42:46 UTC (rev 181671)
@@ -74,5 +74,9 @@
addNewTimer(interval);
}
+void invalidateSharedTimer()
+{
}
+}
+
Modified: trunk/Source/WebCore/platform/gtk/SharedTimerGtk.cpp (181670 => 181671)
--- trunk/Source/WebCore/platform/gtk/SharedTimerGtk.cpp 2015-03-17 23:06:37 UTC (rev 181670)
+++ trunk/Source/WebCore/platform/gtk/SharedTimerGtk.cpp 2015-03-17 23:42:46 UTC (rev 181671)
@@ -57,4 +57,8 @@
gSharedTimer.cancel();
}
+void invalidateSharedTimer()
+{
}
+
+}
Deleted: trunk/Source/WebCore/platform/ios/SharedTimerIOS.mm (181670 => 181671)
--- trunk/Source/WebCore/platform/ios/SharedTimerIOS.mm 2015-03-17 23:06:37 UTC (rev 181670)
+++ trunk/Source/WebCore/platform/ios/SharedTimerIOS.mm 2015-03-17 23:42:46 UTC (rev 181671)
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2006, 2010, 2011, 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "SharedTimer.h"
-
-#import "WebCoreThread.h"
-#import "WebCoreThreadRun.h"
-#import <wtf/Assertions.h>
-
-using namespace WebCore;
-
-namespace WebCore {
-static CFRunLoopTimerRef sharedTimer;
-static void timerFired(CFRunLoopTimerRef, void*);
-
-static void applicationDidBecomeActive(CFNotificationCenterRef, void*, CFStringRef, const void*, CFDictionaryRef)
-{
- WebThreadRun(^{
- if (!sharedTimer)
- return;
-
- stopSharedTimer();
- timerFired(0, 0);
- });
-}
-
-typedef void (*SharedTimerFiredFunction)();
-static SharedTimerFiredFunction sharedTimerFiredFunction;
-
-void setSharedTimerFiredFunction(SharedTimerFiredFunction function)
-{
- ASSERT(!sharedTimerFiredFunction || sharedTimerFiredFunction == function);
-
- sharedTimerFiredFunction = function;
-}
-
-static void timerFired(CFRunLoopTimerRef, void*)
-{
- @autoreleasepool {
- sharedTimerFiredFunction();
- }
-}
-
-void setSharedTimerFireInterval(double interval)
-{
- ASSERT(sharedTimerFiredFunction);
-
- if (sharedTimer) {
- CFRunLoopTimerInvalidate(sharedTimer);
- CFRelease(sharedTimer);
- }
-
- CFAbsoluteTime fireDate = CFAbsoluteTimeGetCurrent() + interval;
- sharedTimer = CFRunLoopTimerCreate(0, fireDate, 0, 0, 0, timerFired, 0);
- CFRunLoopAddTimer(WebThreadRunLoop(), sharedTimer, kCFRunLoopCommonModes);
-
- static bool registeredForApplicationNotification = false;
- if (!registeredForApplicationNotification) {
- registeredForApplicationNotification = true;
- CFNotificationCenterRef notificationCenter = CFNotificationCenterGetLocalCenter();
- CFNotificationCenterAddObserver(notificationCenter, 0, applicationDidBecomeActive, CFSTR("UIApplicationDidBecomeActiveNotification"), NULL, CFNotificationSuspensionBehaviorCoalesce);
- }
-}
-
-void stopSharedTimer()
-{
- if (!sharedTimer)
- return;
-
- CFRunLoopTimerInvalidate(sharedTimer);
- CFRelease(sharedTimer);
- sharedTimer = 0;
-}
-
-} // namespace WebCore
Copied: trunk/Source/WebCore/platform/mac/PowerObserverMac.h (from rev 181670, trunk/Source/WebCore/platform/efl/SharedTimerEfl.cpp) (0 => 181671)
--- trunk/Source/WebCore/platform/mac/PowerObserverMac.h (rev 0)
+++ trunk/Source/WebCore/platform/mac/PowerObserverMac.h 2015-03-17 23:42:46 UTC (rev 181671)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2006, 2010, 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PowerObserverMac_h
+#define PowerObserverMac_h
+
+#import <IOKit/IOMessage.h>
+#import <IOKit/pwr_mgt/IOPMLib.h>
+#import <functional>
+#import <wtf/Noncopyable.h>
+
+namespace WebCore {
+
+class PowerObserver {
+ WTF_MAKE_NONCOPYABLE(PowerObserver);
+
+public:
+ PowerObserver(const std::function<void()>& powerOnHander);
+ ~PowerObserver();
+
+private:
+ void didReceiveSystemPowerNotification(io_service_t, uint32_t messageType, void* messageArgument);
+
+ std::function<void()> m_powerOnHander;
+ io_connect_t m_powerConnection;
+ IONotificationPortRef m_notificationPort;
+ io_object_t m_notifierReference;
+ dispatch_queue_t m_dispatchQueue;
+};
+
+} // namespace WebCore
+
+#endif // PowerObserverMac_h
+
Copied: trunk/Source/WebCore/platform/mac/PowerObserverMac.mm (from rev 181670, trunk/Source/WebCore/platform/mac/SharedTimerMac.mm) (0 => 181671)
--- trunk/Source/WebCore/platform/mac/PowerObserverMac.mm (rev 0)
+++ trunk/Source/WebCore/platform/mac/PowerObserverMac.mm 2015-03-17 23:42:46 UTC (rev 181671)
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2006, 2010, 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+
+#if PLATFORM(MAC)
+#import "PowerObserverMac.h"
+
+namespace WebCore {
+
+PowerObserver::PowerObserver(const std::function<void()>& powerOnHander)
+ : m_powerOnHander(powerOnHander)
+ , m_powerConnection(0)
+ , m_notificationPort(nullptr)
+ , m_notifierReference(0)
+ , m_dispatchQueue(dispatch_queue_create("com.apple.WebKit.PowerObserver", 0))
+{
+ m_powerConnection = IORegisterForSystemPower(this, &m_notificationPort, [](void* context, io_service_t service, uint32_t messageType, void* messageArgument) {
+ static_cast<PowerObserver*>(context)->didReceiveSystemPowerNotification(service, messageType, messageArgument);
+ }, &m_notifierReference);
+ if (!m_powerConnection)
+ return;
+
+ IONotificationPortSetDispatchQueue(m_notificationPort, m_dispatchQueue);
+}
+
+PowerObserver::~PowerObserver()
+{
+ if (!m_powerConnection)
+ return;
+
+ dispatch_release(m_dispatchQueue);
+
+ IODeregisterForSystemPower(&m_notifierReference);
+ IOServiceClose(m_powerConnection);
+ IONotificationPortDestroy(m_notificationPort);
+}
+
+void PowerObserver::didReceiveSystemPowerNotification(io_service_t, uint32_t messageType, void* messageArgument)
+{
+ IOAllowPowerChange(m_powerConnection, reinterpret_cast<long>(messageArgument));
+
+ // We only care about the "wake from sleep" message.
+ if (messageType != kIOMessageSystemWillPowerOn)
+ return;
+
+ // We need to restart the timer on the main thread.
+ CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopCommonModes, ^() {
+ m_powerOnHander();
+ });
+}
+
+} // namespace WebCore
+
+#endif
Deleted: trunk/Source/WebCore/platform/mac/SharedTimerMac.mm (181670 => 181671)
--- trunk/Source/WebCore/platform/mac/SharedTimerMac.mm 2015-03-17 23:06:37 UTC (rev 181670)
+++ trunk/Source/WebCore/platform/mac/SharedTimerMac.mm 2015-03-17 23:42:46 UTC (rev 181671)
@@ -1,154 +0,0 @@
-/*
- * Copyright (C) 2006, 2010 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "SharedTimer.h"
-
-#import <IOKit/IOMessage.h>
-#import <IOKit/pwr_mgt/IOPMLib.h>
-#import <stdio.h>
-#import <wtf/Assertions.h>
-#import <wtf/Noncopyable.h>
-#import <wtf/PassOwnPtr.h>
-
-namespace WebCore {
-
-static CFRunLoopTimerRef sharedTimer;
-static void (*sharedTimerFiredFunction)();
-static void timerFired(CFRunLoopTimerRef, void*);
-
-class PowerObserver {
- WTF_MAKE_NONCOPYABLE(PowerObserver);
-
-public:
- PowerObserver();
- ~PowerObserver();
-
-private:
- void didReceiveSystemPowerNotification(io_service_t, uint32_t messageType, void* messageArgument);
-
- void restartSharedTimer();
-
- io_connect_t m_powerConnection;
- IONotificationPortRef m_notificationPort;
- io_object_t m_notifierReference;
- dispatch_queue_t m_dispatchQueue;
-};
-
-PowerObserver::PowerObserver()
- : m_powerConnection(0)
- , m_notificationPort(nullptr)
- , m_notifierReference(0)
- , m_dispatchQueue(dispatch_queue_create("com.apple.WebKit.PowerObserver", 0))
-{
- m_powerConnection = IORegisterForSystemPower(this, &m_notificationPort, [](void* context, io_service_t service, uint32_t messageType, void* messageArgument) {
- static_cast<PowerObserver*>(context)->didReceiveSystemPowerNotification(service, messageType, messageArgument);
- }, &m_notifierReference);
- if (!m_powerConnection)
- return;
-
- IONotificationPortSetDispatchQueue(m_notificationPort, m_dispatchQueue);
-}
-
-PowerObserver::~PowerObserver()
-{
- if (!m_powerConnection)
- return;
-
- dispatch_release(m_dispatchQueue);
-
- IODeregisterForSystemPower(&m_notifierReference);
- IOServiceClose(m_powerConnection);
- IONotificationPortDestroy(m_notificationPort);
-}
-
-void PowerObserver::didReceiveSystemPowerNotification(io_service_t, uint32_t messageType, void* messageArgument)
-{
- IOAllowPowerChange(m_powerConnection, reinterpret_cast<long>(messageArgument));
-
- // We only care about the "wake from sleep" message.
- if (messageType != kIOMessageSystemWillPowerOn)
- return;
-
- // We need to restart the timer on the main thread.
- CFRunLoopPerformBlock(CFRunLoopGetMain(), kCFRunLoopCommonModes, ^() {
- restartSharedTimer();
- });
-}
-
-void PowerObserver::restartSharedTimer()
-{
- ASSERT(CFRunLoopGetCurrent() == CFRunLoopGetMain());
-
- if (!sharedTimer)
- return;
-
- stopSharedTimer();
- timerFired(0, 0);
-}
-
-static PowerObserver* powerObserver;
-
-void setSharedTimerFiredFunction(void (*f)())
-{
- ASSERT(!sharedTimerFiredFunction || sharedTimerFiredFunction == f);
-
- sharedTimerFiredFunction = f;
-}
-
-static void timerFired(CFRunLoopTimerRef, void*)
-{
- @autoreleasepool {
- sharedTimerFiredFunction();
- }
-}
-
-void setSharedTimerFireInterval(double interval)
-{
- ASSERT(sharedTimerFiredFunction);
-
- if (sharedTimer) {
- CFRunLoopTimerInvalidate(sharedTimer);
- CFRelease(sharedTimer);
- }
-
- CFAbsoluteTime fireDate = CFAbsoluteTimeGetCurrent() + interval;
- sharedTimer = CFRunLoopTimerCreate(0, fireDate, 0, 0, 0, timerFired, 0);
- CFRunLoopAddTimer(CFRunLoopGetCurrent(), sharedTimer, kCFRunLoopCommonModes);
-
- if (!powerObserver)
- powerObserver = std::make_unique<PowerObserver>().release();
-}
-
-void stopSharedTimer()
-{
- if (sharedTimer) {
- CFRunLoopTimerInvalidate(sharedTimer);
- CFRelease(sharedTimer);
- sharedTimer = 0;
- }
-}
-
-} // namespace WebCore
Modified: trunk/Source/WebCore/platform/win/SharedTimerWin.cpp (181670 => 181671)
--- trunk/Source/WebCore/platform/win/SharedTimerWin.cpp 2015-03-17 23:06:37 UTC (rev 181670)
+++ trunk/Source/WebCore/platform/win/SharedTimerWin.cpp 2015-03-17 23:42:46 UTC (rev 181671)
@@ -198,4 +198,8 @@
}
}
+void invalidateSharedTimer()
+{
}
+
+}