Bug 896896. Use MsgWaitForMultipleObjectsEx instead of WaitMessage. r=roc

--HG--
extra : rebase_source : 4e63339d0aa2ca732c1d12c4abcf891b70ee0056
This commit is contained in:
Nicholas Cameron 2013-07-31 08:51:45 +12:00
Родитель 60765a4876
Коммит 71e821ee4d
4 изменённых файлов: 37 добавлений и 2 удалений

Просмотреть файл

@ -127,6 +127,28 @@ WinUtils::GetMessage(LPMSG aMsg, HWND aWnd, UINT aFirstMessage,
return ::GetMessageW(aMsg, aWnd, aFirstMessage, aLastMessage);
}
/* static */
void
WinUtils::WaitForMessage()
{
DWORD result = ::MsgWaitForMultipleObjectsEx(0, NULL, INFINITE, QS_ALLINPUT,
MWMO_INPUTAVAILABLE);
NS_WARN_IF_FALSE(result != WAIT_FAILED, "Wait failed");
// This idiom is taken from the Chromium ipc code, see
// ipc/chromium/src/base/message+puimp_win.cpp:270.
// The intent is to avoid a busy wait when MsgWaitForMultipleObjectsEx
// returns quickly but PeekMessage would not return a message.
if (result == WAIT_OBJECT_0) {
MSG msg = {0};
DWORD queue_status = ::GetQueueStatus(QS_MOUSE);
if (HIWORD(queue_status) & QS_MOUSE &&
!PeekMessage(&msg, NULL, WM_MOUSEFIRST, WM_MOUSELAST, PM_NOREMOVE)) {
::WaitMessage();
}
}
}
/* static */
bool
WinUtils::GetRegistryKey(HKEY aRoot,

Просмотреть файл

@ -64,6 +64,19 @@ public:
UINT aLastMessage, UINT aOption);
static bool GetMessage(LPMSG aMsg, HWND aWnd, UINT aFirstMessage,
UINT aLastMessage);
/**
* Wait until a message is ready to be processed.
* Prefer using this method to directly calling ::WaitMessage since
* ::WaitMessage will wait if there is an unread message in the queue.
* That can cause freezes until another message enters the queue if the
* message is marked read by a call to PeekMessage which the caller is
* not aware of (e.g., from a different thread).
* Note that this method may cause sync dispatch of sent (as opposed to
* posted) messages.
*/
static void WaitForMessage();
/**
* Gets the value of a string-typed registry value.
*

Просмотреть файл

@ -225,7 +225,7 @@ nsAppShell::ProcessNextNativeEvent(bool mayWait)
} else if (mayWait) {
// Block and wait for any posted application message
mozilla::HangMonitor::Suspend();
::WaitMessage();
WinUtils::WaitForMessage();
}
} while (!gotMessage && mayWait);

Просмотреть файл

@ -143,7 +143,7 @@ MetroAppShell::ProcessNextNativeEvent(bool mayWait)
if (mayWait) {
if (!WinUtils::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
WaitMessage();
WinUtils::WaitForMessage();
}
ProcessOneNativeEventIfPresent();
return true;