Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(629)

Unified Diff: base/message_loop/message_pump_win.cc

Issue 1953393002: Stop using WaitMessage in MessagePumpForUI::WaitForWork (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop/message_pump_win.cc
diff --git a/base/message_loop/message_pump_win.cc b/base/message_loop/message_pump_win.cc
index cb68a24d74a2979ece7ef57076a80e27ac3d788c..9729e4d651b3c8ee097c6c8b2ca26019f3e9fab1 100644
--- a/base/message_loop/message_pump_win.cc
+++ b/base/message_loop/message_pump_win.cc
@@ -220,37 +220,46 @@ void MessagePumpForUI::InitMessageWnd() {
void MessagePumpForUI::WaitForWork() {
// Wait until a message is available, up to the time needed by the timer
// manager to fire the next set of timers.
- int delay = GetCurrentDelay();
- if (delay < 0) // Negative value means no timers waiting.
- delay = INFINITE;
-
- DWORD result;
- result = MsgWaitForMultipleObjectsEx(0, NULL, delay, QS_ALLINPUT,
- MWMO_INPUTAVAILABLE);
-
- if (WAIT_OBJECT_0 == result) {
- // A WM_* message is available.
- // If a parent child relationship exists between windows across threads
- // then their thread inputs are implicitly attached.
- // This causes the MsgWaitForMultipleObjectsEx API to return indicating
- // that messages are ready for processing (Specifically, mouse messages
- // intended for the child window may appear if the child window has
- // capture).
- // The subsequent PeekMessages call may fail to return any messages thus
- // causing us to enter a tight loop at times.
- // The WaitMessage call below is a workaround to give the child window
- // some time to process its input messages.
- MSG msg = {0};
- bool has_pending_sent_message =
- (HIWORD(GetQueueStatus(QS_SENDMESSAGE)) & QS_SENDMESSAGE) != 0;
- if (!has_pending_sent_message &&
- !PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
- WaitMessage();
+ int delay;
+ DWORD wait_flags = MWMO_INPUTAVAILABLE;
+
+ while ((delay = GetCurrentDelay()) != 0) {
danakj 2016/05/11 01:13:36 The old code when delay was 0 would call MsgWaitFo
stanisc 2016/05/11 01:46:41 You are right. This is a suble difference with the
+ if (delay < 0) // Negative value means no timers waiting.
+ delay = INFINITE;
+
+ DWORD result =
+ MsgWaitForMultipleObjectsEx(0, NULL, delay, QS_ALLINPUT, wait_flags);
+
+ if (WAIT_OBJECT_0 == result) {
+ // A WM_* message is available.
+ // If a parent child relationship exists between windows across threads
+ // then their thread inputs are implicitly attached.
+ // This causes the MsgWaitForMultipleObjectsEx API to return indicating
+ // that messages are ready for processing (Specifically, mouse messages
+ // intended for the child window may appear if the child window has
+ // capture).
+ // The subsequent PeekMessages call may fail to return any messages thus
+ // causing us to enter a tight loop at times.
+ // The code below is a workaround to give the child window
+ // some time to process its input messages by looping back to
+ // MsgWaitForMultipleObjectsEx above when there are no messages for the
+ // current thread.
+ MSG msg = {0};
+ bool has_pending_sent_message =
+ (HIWORD(GetQueueStatus(QS_SENDMESSAGE)) & QS_SENDMESSAGE) != 0;
+ if (has_pending_sent_message ||
+ PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) {
+ return;
+ }
+
+ // We know there are no more messages for this thread because PeekMessage
+ // has returned false. Reset |wait_flags| so that we wait for a *new*
+ // message.
+ wait_flags = 0;
}
- return;
- }
- DCHECK_NE(WAIT_FAILED, result) << GetLastError();
+ DCHECK_NE(WAIT_FAILED, result) << GetLastError();
+ }
}
void MessagePumpForUI::HandleWorkMessage() {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698