OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/message_loop/message_pump_win.h" | 5 #include "base/message_loop/message_pump_win.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 | 505 |
506 WaitForWork(); // Wait (sleep) until we have work to do again. | 506 WaitForWork(); // Wait (sleep) until we have work to do again. |
507 } | 507 } |
508 } | 508 } |
509 | 509 |
510 void MessagePumpForGpu::WaitForWork() { | 510 void MessagePumpForGpu::WaitForWork() { |
511 // Wait until a message is available, up to the time needed by the timer | 511 // Wait until a message is available, up to the time needed by the timer |
512 // manager to fire the next set of timers. | 512 // manager to fire the next set of timers. |
513 int delay; | 513 int delay; |
514 | 514 |
515 // TODO(stanisc): crbug.com/596190: Preserve |result| for crash dump analysis | |
516 // with initial value different from values returned by | |
517 // MsgWaitForMultipleObjectsEx. | |
518 DWORD result = static_cast<DWORD>(-1); | |
519 debug::Alias(&result); | |
520 | |
515 // The while loop handles the situation where on Windows 7 and later versions | 521 // The while loop handles the situation where on Windows 7 and later versions |
516 // MsgWaitForMultipleObjectsEx might time out slightly earlier (less than one | 522 // MsgWaitForMultipleObjectsEx might time out slightly earlier (less than one |
517 // ms) than the specified |delay|. In that situation it is more optimal to | 523 // ms) than the specified |delay|. In that situation it is more optimal to |
518 // just wait again rather than waste a DoRunLoop cycle. | 524 // just wait again rather than waste a DoRunLoop cycle. |
519 while ((delay = GetCurrentDelay()) != 0) { | 525 while ((delay = GetCurrentDelay()) != 0) { |
520 if (delay < 0) // Negative value means no timers waiting. | 526 if (delay < 0) // Negative value means no timers waiting. |
521 delay = INFINITE; | 527 delay = INFINITE; |
522 | 528 |
523 DWORD result = | 529 result = MsgWaitForMultipleObjectsEx(1, &event_, delay, QS_ALLINPUT, 0); |
524 MsgWaitForMultipleObjectsEx(1, &event_, delay, QS_ALLINPUT, 0); | |
525 if (result == WAIT_OBJECT_0) { | 530 if (result == WAIT_OBJECT_0) { |
526 // Work available. | 531 // Work available. |
527 return; | 532 return; |
528 } else if (result == WAIT_OBJECT_0 + 1) { | 533 } else if (result == WAIT_OBJECT_0 + 1) { |
529 // Message available. Keep waiting if this message isn't for this thread. | 534 // Message available (regardless of whether |event_| is also signalled at |
535 // the same time). | |
536 | |
537 // Break the loop if the work is available - PeekMessage will still be | |
538 // called outside, in ProcessNextMessage. | |
539 if (WaitForSingleObject(event_, 0) == WAIT_OBJECT_0) | |
brucedawson
2016/06/03 00:18:30
Previously this loop would favor window messages o
| |
540 return; | |
541 | |
542 // Keep waiting if this message isn't for this thread. | |
530 MSG msg; | 543 MSG msg; |
531 if (PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE)) | 544 if (PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE)) |
532 return; | 545 return; |
533 } | 546 } |
534 | 547 |
535 DCHECK_NE(WAIT_FAILED, result) << GetLastError(); | 548 DCHECK_NE(WAIT_FAILED, result) << GetLastError(); |
536 } | 549 } |
537 } | 550 } |
538 | 551 |
539 bool MessagePumpForGpu::ProcessNextMessage() { | 552 bool MessagePumpForGpu::ProcessNextMessage() { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 if (!filter || it->handler == filter) { | 741 if (!filter || it->handler == filter) { |
729 *item = *it; | 742 *item = *it; |
730 completed_io_.erase(it); | 743 completed_io_.erase(it); |
731 return true; | 744 return true; |
732 } | 745 } |
733 } | 746 } |
734 return false; | 747 return false; |
735 } | 748 } |
736 | 749 |
737 } // namespace base | 750 } // namespace base |
OLD | NEW |