mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 670967 - Part 1: Add mozilla::ScheduleMemoryPressureEvent(). r=bsmedberg
This commit is contained in:
parent
e3decbb3a4
commit
44fb6c8cea
@ -64,6 +64,7 @@ CPPSRCS = \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsThread.h \
|
||||
nsProcess.h \
|
||||
nsEventQueue.h \
|
||||
nsThreadUtilsInternal.h \
|
||||
|
@ -45,7 +45,9 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "prlog.h"
|
||||
#include "nsThreadUtilsInternal.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "mozilla/HangMonitor.h"
|
||||
#include "mozilla/Services.h"
|
||||
|
||||
#define HAVE_UALARM _BSD_SOURCE || (_XOPEN_SOURCE >= 500 || \
|
||||
_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && \
|
||||
@ -81,6 +83,21 @@ NS_DECL_CI_INTERFACE_GETTER(nsThread)
|
||||
|
||||
nsIThreadObserver* nsThread::sGlobalObserver;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
static volatile bool sMemoryPressurePending = false;
|
||||
|
||||
/*
|
||||
* It's important that this function not acquire any locks, nor do anything
|
||||
* which might cause malloc to run.
|
||||
*/
|
||||
void ScheduleMemoryPressureEvent()
|
||||
{
|
||||
PR_ATOMIC_SET(&sMemoryPressurePending, true);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Because we do not have our own nsIFactory, we have to implement nsIClassInfo
|
||||
// somewhat manually.
|
||||
@ -577,6 +594,22 @@ nsThread::ProcessNextEvent(bool mayWait, bool *result)
|
||||
if (MAIN_THREAD == mIsMainThread && mayWait && !ShuttingDown())
|
||||
HangMonitor::Suspend();
|
||||
|
||||
// Fire a memory pressure notification, if we're the main thread and one is
|
||||
// pending.
|
||||
if (MAIN_THREAD == mIsMainThread && !ShuttingDown()) {
|
||||
bool mpPending = PR_ATOMIC_SET(&sMemoryPressurePending, false);
|
||||
if (mpPending) {
|
||||
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
||||
if (os) {
|
||||
os->NotifyObservers(nsnull, "memory-pressure",
|
||||
NS_LITERAL_STRING("low-memory").get());
|
||||
}
|
||||
else {
|
||||
NS_WARNING("Can't get observer service!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool notifyGlobalObserver = (sGlobalObserver != nsnull);
|
||||
if (notifyGlobalObserver)
|
||||
sGlobalObserver->OnProcessNextEvent(this, mayWait && !ShuttingDown(),
|
||||
|
@ -178,4 +178,16 @@ private:
|
||||
nsresult mResult;
|
||||
};
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
/**
|
||||
* This function causes the main thread to fire a memory pressure event at its
|
||||
* next available opportunity.
|
||||
*
|
||||
* You may call this function from any thread.
|
||||
*/
|
||||
void ScheduleMemoryPressureEvent();
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // nsThread_h__
|
||||
|
Loading…
Reference in New Issue
Block a user