Bug 905405. Wrap mLastNativeEventScheduled in a mutex to avoid racing on it. r=bsmedberg

This commit is contained in:
Robert O'Callahan 2013-09-19 16:24:34 +12:00
parent 294cedd09d
commit 729180d69e
2 changed files with 18 additions and 6 deletions

View File

@ -161,9 +161,12 @@ nsAppShell::ScheduleNativeEventCallback()
{
// Post a message to the hidden message window
NS_ADDREF_THIS(); // will be released when the event is processed
// Time stamp this event so we can detect cases where the event gets
// dropping in sub classes / modal loops we do not control.
mLastNativeEventScheduled = TimeStamp::NowLoRes();
{
MutexAutoLock lock(mLastNativeEventScheduledMutex);
// Time stamp this event so we can detect cases where the event gets
// dropping in sub classes / modal loops we do not control.
mLastNativeEventScheduled = TimeStamp::NowLoRes();
}
::PostMessage(mEventWnd, sAppShellGeckoMsgId, 0, reinterpret_cast<LPARAM>(this));
}
@ -238,8 +241,13 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
static const mozilla::TimeDuration nativeEventStarvationLimit =
mozilla::TimeDuration::FromSeconds(NATIVE_EVENT_STARVATION_LIMIT);
if ((TimeStamp::NowLoRes() - mLastNativeEventScheduled) >
nativeEventStarvationLimit) {
TimeDuration timeSinceLastNativeEventScheduled;
{
MutexAutoLock lock(mLastNativeEventScheduledMutex);
timeSinceLastNativeEventScheduled =
TimeStamp::NowLoRes() - mLastNativeEventScheduled;
}
if (timeSinceLastNativeEventScheduled > nativeEventStarvationLimit) {
ScheduleNativeEventCallback();
}

View File

@ -9,6 +9,7 @@
#include "nsBaseAppShell.h"
#include <windows.h>
#include "mozilla/TimeStamp.h"
#include "mozilla/Mutex.h"
// The maximum time we allow before forcing a native event callback.
// In seconds.
@ -22,7 +23,8 @@ class nsAppShell : public nsBaseAppShell
public:
nsAppShell() :
mEventWnd(NULL),
mNativeCallbackPending(false)
mNativeCallbackPending(false),
mLastNativeEventScheduledMutex("nsAppShell::mLastNativeEventScheduledMutex")
{}
typedef mozilla::TimeStamp TimeStamp;
@ -43,6 +45,8 @@ protected:
protected:
HWND mEventWnd;
bool mNativeCallbackPending;
Mutex mLastNativeEventScheduledMutex;
TimeStamp mLastNativeEventScheduled;
};