Bug 516769 - WINCE IsLowMemory fixups. r=vlad
authorDoug Turner <dougt@meer.net>
Tue, 15 Sep 2009 13:29:57 -0700
changeset 32507 9a19776b0676fafda4df33a82879ea01440fd017
parent 32506 9c3a70ea7acf1cbec97427a319e674bc77818d3a
child 32508 c5ef50d41b47b0ec88306e886fd7880072984956
push id9130
push userdougt@mozilla.com
push dateTue, 15 Sep 2009 20:30:08 +0000
treeherdermozilla-central@9a19776b0676 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvlad
bugs516769
milestone1.9.3a1pre
Bug 516769 - WINCE IsLowMemory fixups. r=vlad
xpcom/base/nsMemoryImpl.cpp
--- a/xpcom/base/nsMemoryImpl.cpp
+++ b/xpcom/base/nsMemoryImpl.cpp
@@ -67,16 +67,19 @@ const char* kHighMark = "/sys/kernel/hig
 // Some platforms notify you when system memory is low, others do not.
 // In the case of those that do not, we want to post low memory
 // notifications from IsLowMemory().  For those that can notify us, that
 // code usually lives in toolkit.
 #ifdef WINCE
 #define NOTIFY_LOW_MEMORY
 #endif
 
+#ifdef WINCE_WINDOWS_MOBILE
+#include "aygshell.h"
+#endif
 
 #include "nsITimer.h"
 
 static nsMemoryImpl sGlobalMemory;
 
 NS_IMPL_QUERY_INTERFACE1(nsMemoryImpl, nsIMemory)
 
 NS_IMETHODIMP_(void*)
@@ -110,17 +113,17 @@ nsMemoryImpl::HeapMinimize(PRBool aImmed
 static const int kRequiredMemory = 0x3000000;
 
 NS_IMETHODIMP
 nsMemoryImpl::IsLowMemory(PRBool *result)
 {
 #if defined(WINCE)
     MEMORYSTATUS stat;
     GlobalMemoryStatus(&stat);
-    *result = (stat.dwMemoryLoad >= 90);
+    *result = (stat.dwMemoryLoad >= 80);
 #elif defined(XP_WIN)
     MEMORYSTATUSEX stat;
     stat.dwLength = sizeof stat;
     GlobalMemoryStatusEx(&stat);
     *result = (stat.ullAvailPageFile < kRequiredMemory) &&
         ((float)stat.ullAvailPageFile / stat.ullTotalPageFile) < 0.1;
 #elif defined(NS_OSSO)
     int fd = open (kHighMark, O_RDONLY);
@@ -212,19 +215,29 @@ nsMemoryImpl::RunFlushers(const PRUnicha
               e->GetNext(getter_AddRefs(observer));
 
               if (!observer)
                   continue;
 
               observer->Observe(observer, "memory-pressure", aReason);
           }
         }
-        //       
     }
 
+    // Run built-in system flushers
+#ifdef WINCE_WINDOWS_MOBILE
+
+    // This function tries to free up memory for an application.
+    // If necessary, the shell closes down other applications by
+    // sending WM_CLOSE messages.  We ask for 4MB.
+
+    SHCloseApps(1024 * 1024 * 4);
+
+#endif
+
     sIsFlushing = 0;
     return NS_OK;
 }
 
 // XXX need NS_IMPL_STATIC_ADDREF/RELEASE
 NS_IMETHODIMP_(nsrefcnt) nsMemoryImpl::FlushEvent::AddRef() { return 2; }
 NS_IMETHODIMP_(nsrefcnt) nsMemoryImpl::FlushEvent::Release() { return 1; }
 NS_IMPL_QUERY_INTERFACE1(nsMemoryImpl::FlushEvent, nsIRunnable)