зеркало из https://github.com/mozilla/pjs.git
Bug 44352. Adding IsLowMemory predicate & implementation for Windows.
This commit is contained in:
Родитель
126a33230c
Коммит
3f96fe5c0f
|
@ -98,6 +98,13 @@ interface nsIMemory : nsISupports
|
|||
* @param obs - the observer to unregister
|
||||
*/
|
||||
void unregisterObserver(in nsIMemoryPressureObserver obs);
|
||||
|
||||
/**
|
||||
* This predicate can be used to determine if we're in a low-memory
|
||||
* situation (what constitutes low-memory is platform dependent). This
|
||||
* can be used to trigger the memory flushers.
|
||||
*/
|
||||
boolean isLowMemory();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,6 +24,10 @@
|
|||
#include "prmem.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#ifdef XP_PC
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMemoryImpl, nsIMemory)
|
||||
|
||||
NS_METHOD
|
||||
|
@ -46,7 +50,7 @@ nsMemoryImpl::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Define NS_OUT_OF_MEMORY_TESTER if you want to force memory failures
|
||||
|
||||
#ifdef DEBUG_warren
|
||||
#ifdef DEBUG_xwarren
|
||||
#define NS_OUT_OF_MEMORY_TESTER
|
||||
#endif
|
||||
|
||||
|
@ -164,6 +168,20 @@ nsMemoryImpl::UnregisterObserver(nsIMemoryPressureObserver* obs)
|
|||
return mObservers->RemoveElement(obs);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryImpl::IsLowMemory(PRBool *result)
|
||||
{
|
||||
#ifdef XP_PC
|
||||
MEMORYSTATUS stat;
|
||||
GlobalMemoryStatus(&stat);
|
||||
*result = ((float)stat.dwAvailPageFile / stat.dwTotalPageFile) < 0.1;
|
||||
return NS_OK;
|
||||
#else
|
||||
NS_NOTREACHED("nsMemoryImpl::IsLowMemory");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMemoryImpl::FlushMemory(PRUint32 reason, PRSize size)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче