webengine/osswebengine/MemoryManager/Src/StopScheduler.cpp
branchRCL_3
changeset 91 30342f40acbf
parent 0 dd21522fd290
child 93 79859ed3eea9
--- a/webengine/osswebengine/MemoryManager/Src/StopScheduler.cpp	Mon Jun 21 16:54:17 2010 +0300
+++ b/webengine/osswebengine/MemoryManager/Src/StopScheduler.cpp	Thu Jul 15 19:53:20 2010 +0300
@@ -18,10 +18,10 @@
 #include "StopScheduler.h"
 #include "MemoryPool.h"
 #include "fast_malloc.h"
+#include "MemoryLogger.h"
+#include <hal.h>
 
 // MEMBER FUNCTIONS
-static const TUint KLessRAM = ( 2*1024*1024 );
-static const TUint KMinimumRAM = (1024 * 1024);
 static const TTimeIntervalMicroSeconds32 KMemoryCheckIntervalSlow = 1000000;        // 1 second
 static const TTimeIntervalMicroSeconds32 KMemoryCheckIntervalFast = 500000;         // 0.5 second
 
@@ -81,26 +81,33 @@
         }
     else if( iState == ECheckMemory )
         {
-        TFreeMem freeMem;
-        TInt total = iMemoryPool.FreeMemory( freeMem );
-
-        // see if free memory is enough to restore all collectors
-        if( freeMem.iHal >= KLessRAM )
+    
+        TInt systemFreeRAM; 
+        if(HAL::Get(HALData::EMemoryRAMFree, systemFreeRAM) != KErrNone) 
+            return;        
+        
+        // case 1: Good memory levels - no worry
+        if( systemFreeRAM > KGoodMemoryThreshold ) // Above 4MB
             {
-            iMemoryPool.RestoreCollectors( EOOM_PriorityLow );
+            iMemoryPool.RestoreCollectors( EOOM_PriorityLow ); // restore all collectors
             iState = EIdle;
             iNextStop = EAllStop;
 
             // recover the rescue buffer, if it is already released.
             iMemoryPool.RestoreRescueBuffer();
+            return;
             }
-        else if( freeMem.iHal >= KMinimumRAM/2 )
+        
+        // case 2: Going low - keep checking
+        if( systemFreeRAM > KLowMemoryThreshold ) // Between 4MB to 2MB
             {
-            iMemoryPool.RestoreCollectors( EOOM_PriorityMiddle );
             CheckMemoryDefered( KMemoryCheckIntervalSlow );
             iNextStop = EAllStop;
+            return;
             }
-        else if( freeMem.iHal >= KMinimumRAM/4 )
+         
+        // case 3: Below normal levels - stop low priority activites
+        if( systemFreeRAM > KStopThreshold )  // Between 2MB to 1MB
             {
             if( iNextStop & ENormalStop ) 
                 {
@@ -108,15 +115,15 @@
                 iNextStop &= ~ENormalStop;
                 }
             CheckMemoryDefered( KMemoryCheckIntervalFast );
-            }
-        else
+            }        
+        else // case 4: Really low - stop in emergency (all activites), below 1MB
             {
             if( iNextStop & EEmergencyStop ) 
                 {
                 StopLoading( EOOM_PriorityHigh );
                 iNextStop &= ~EEmergencyStop;
                 }
-            CheckMemoryDefered( KMemoryCheckIntervalFast );
+            CheckMemoryDefered( KMemoryCheckIntervalSlow ); // need to restore colectors later
             }
         }
     }
@@ -134,6 +141,7 @@
 //-----------------------------------------------------------------------------
 void CStopScheduler::StopLoading( TOOMPriority aPriority )
     {
+    MEM_LOG("CStopScheduler::StopLoading - run");
     // stop operations
     for( TInt i=0; i<iMemoryPool.Stoppers().Count(); ++i )
         {
@@ -141,6 +149,7 @@
         if( stopper->Priority() == aPriority )
             stopper->Stop();
         }
+    iMemoryPool.CollectMemory(2*KGoodMemoryThreshold);  // try to collect memory
     iMemoryPool.SetStopping( EFalse );
     }