[iOS WebKit2] Listen for system memory pressure notifications.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Apr 2014 00:01:33 +0000 (00:01 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Apr 2014 00:01:33 +0000 (00:01 +0000)
<https://webkit.org/b/131653>
<rdar://problem/16208123>

Reviewed by Antti Koivisto.

* platform/cocoa/MemoryPressureHandlerCocoa.mm:
(WebCore::MemoryPressureHandler::install):

    Use the right invocation to summon the memory pressure handler.

(WebCore::MemoryPressureHandler::install):
(WebCore::MemoryPressureHandler::uninstall):
(WebCore::MemoryPressureHandler::holdOff):
(WebCore::MemoryPressureHandler::respondToMemoryPressure):

    Make stubbed out functions !PLATFORM(COCOA)

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@167338 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/MemoryPressureHandler.cpp
Source/WebCore/platform/cocoa/MemoryPressureHandlerCocoa.mm

index e245591..50bccfd 100644 (file)
@@ -1,3 +1,23 @@
+2014-04-15  Andreas Kling  <akling@apple.com>
+
+        [iOS WebKit2] Listen for system memory pressure notifications.
+        <https://webkit.org/b/131653>
+        <rdar://problem/16208123>
+
+        Reviewed by Antti Koivisto.
+
+        * platform/cocoa/MemoryPressureHandlerCocoa.mm:
+        (WebCore::MemoryPressureHandler::install):
+
+            Use the right invocation to summon the memory pressure handler.
+
+        (WebCore::MemoryPressureHandler::install):
+        (WebCore::MemoryPressureHandler::uninstall):
+        (WebCore::MemoryPressureHandler::holdOff):
+        (WebCore::MemoryPressureHandler::respondToMemoryPressure):
+
+            Make stubbed out functions !PLATFORM(COCOA)
+
 2014-04-14  Morten Stenshorne  <mstensho@opera.com>
 
         [New Multicolumn] Add support for column-span:all
index 446ad29..6439614 100644 (file)
@@ -95,14 +95,11 @@ void MemoryPressureHandler::releaseMemory(bool critical)
     WTF::releaseFastMallocFreeMemory();
 }
 
-#if !PLATFORM(MAC)
+#if !PLATFORM(COCOA)
 void MemoryPressureHandler::install() { }
 void MemoryPressureHandler::uninstall() { }
 void MemoryPressureHandler::holdOff(unsigned) { }
 void MemoryPressureHandler::respondToMemoryPressure() { }
-#endif
-
-#if !PLATFORM(COCOA)
 void MemoryPressureHandler::platformReleaseMemory(bool) { }
 #endif
 
index fb92a86..659291e 100644 (file)
@@ -38,6 +38,7 @@
 #if PLATFORM(IOS)
 #import "SystemMemory.h"
 #import "WebCoreThread.h"
+#import <dispatch/private.h>
 #endif
 
 namespace WebCore {
@@ -52,8 +53,6 @@ void MemoryPressureHandler::platformReleaseMemory(bool)
 #endif
 }
 
-#if PLATFORM(MAC)
-
 static dispatch_source_t _cache_event_source = 0;
 static dispatch_source_t _timer_event_source = 0;
 static int _notifyToken;
@@ -73,14 +72,18 @@ void MemoryPressureHandler::install()
         return;
 
     dispatch_async(dispatch_get_main_queue(), ^{
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
+#if PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000
+        _cache_event_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MEMORYSTATUS, 0, DISPATCH_MEMORYSTATUS_PRESSURE_WARN, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
+#elif PLATFORM(MAC) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
         _cache_event_source = wkCreateMemoryStatusPressureCriticalDispatchOnMainQueue();
 #else
         _cache_event_source = wkCreateVMPressureDispatchOnMainQueue();
 #endif
         if (_cache_event_source) {
             dispatch_set_context(_cache_event_source, this);
-            dispatch_source_set_event_handler(_cache_event_source, ^{ memoryPressureHandler().respondToMemoryPressure();});
+            dispatch_source_set_event_handler(_cache_event_source, ^{
+                memoryPressureHandler().respondToMemoryPressure();
+            });
             dispatch_resume(_cache_event_source);
         }
     });
@@ -156,8 +159,7 @@ void MemoryPressureHandler::respondToMemoryPressure()
     holdOff(std::max(holdOffTime, s_minimumHoldOffTime));
 }
 
-#else // !PLATFORM(MAC)
-
+#if PLATFORM(IOS)
 static void respondToMemoryPressureCallback(CFRunLoopObserverRef observer, CFRunLoopActivity /*activity*/, void* /*info*/)
 {
     memoryPressureHandler().respondToMemoryPressureIfNeeded();