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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 | 442 |
443 // static | 443 // static |
444 std::unique_ptr<MessagePump> MessagePumpForGpu::CreateMessagePumpForGpu() { | 444 std::unique_ptr<MessagePump> MessagePumpForGpu::CreateMessagePumpForGpu() { |
445 return WrapUnique<MessagePump>(new MessagePumpForGpu); | 445 return WrapUnique<MessagePump>(new MessagePumpForGpu); |
446 } | 446 } |
447 | 447 |
448 void MessagePumpForGpu::ScheduleWork() { | 448 void MessagePumpForGpu::ScheduleWork() { |
449 if (InterlockedExchange(&work_state_, HAVE_WORK) != READY) | 449 if (InterlockedExchange(&work_state_, HAVE_WORK) != READY) |
450 return; // Someone else continued the pumping. | 450 return; // Someone else continued the pumping. |
451 | 451 |
| 452 // TODO(stanisc): crbug.com/596190: Preserve for crash dump analysis. |
| 453 // Remove this when the bug is fixed. |
| 454 last_set_event_timeticks_ = TimeTicks::Now(); |
| 455 |
452 // Make sure the MessagePump does some work for us. | 456 // Make sure the MessagePump does some work for us. |
453 SetEvent(event_); | 457 SetEvent(event_); |
454 } | 458 } |
455 | 459 |
456 void MessagePumpForGpu::ScheduleDelayedWork( | 460 void MessagePumpForGpu::ScheduleDelayedWork( |
457 const TimeTicks& delayed_work_time) { | 461 const TimeTicks& delayed_work_time) { |
458 // We know that we can't be blocked right now since this method can only be | 462 // We know that we can't be blocked right now since this method can only be |
459 // called on the same thread as Run, so we only need to update our record of | 463 // called on the same thread as Run, so we only need to update our record of |
460 // how long to sleep when we do sleep. | 464 // how long to sleep when we do sleep. |
461 delayed_work_time_ = delayed_work_time; | 465 delayed_work_time_ = delayed_work_time; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 int delay; | 517 int delay; |
514 | 518 |
515 // The while loop handles the situation where on Windows 7 and later versions | 519 // The while loop handles the situation where on Windows 7 and later versions |
516 // MsgWaitForMultipleObjectsEx might time out slightly earlier (less than one | 520 // MsgWaitForMultipleObjectsEx might time out slightly earlier (less than one |
517 // ms) than the specified |delay|. In that situation it is more optimal to | 521 // ms) than the specified |delay|. In that situation it is more optimal to |
518 // just wait again rather than waste a DoRunLoop cycle. | 522 // just wait again rather than waste a DoRunLoop cycle. |
519 while ((delay = GetCurrentDelay()) != 0) { | 523 while ((delay = GetCurrentDelay()) != 0) { |
520 if (delay < 0) // Negative value means no timers waiting. | 524 if (delay < 0) // Negative value means no timers waiting. |
521 delay = INFINITE; | 525 delay = INFINITE; |
522 | 526 |
| 527 // TODO(stanisc): crbug.com/596190: Preserve for crash dump analysis. |
| 528 // Remove this when the bug is fixed. |
| 529 TimeTicks wait_for_work_timeticks = TimeTicks::Now(); |
| 530 debug::Alias(&wait_for_work_timeticks); |
| 531 debug::Alias(&delay); |
| 532 |
523 DWORD result = | 533 DWORD result = |
524 MsgWaitForMultipleObjectsEx(1, &event_, delay, QS_ALLINPUT, 0); | 534 MsgWaitForMultipleObjectsEx(1, &event_, delay, QS_ALLINPUT, 0); |
525 if (result == WAIT_OBJECT_0) { | 535 DCHECK_NE(WAIT_FAILED, result) << GetLastError(); |
526 // Work available. | 536 if (result != WAIT_TIMEOUT) { |
| 537 // Either work or message available. |
527 return; | 538 return; |
528 } else if (result == WAIT_OBJECT_0 + 1) { | |
529 // Message available. Keep waiting if this message isn't for this thread. | |
530 MSG msg; | |
531 if (PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE)) | |
532 return; | |
533 } | 539 } |
534 | |
535 DCHECK_NE(WAIT_FAILED, result) << GetLastError(); | |
536 } | 540 } |
537 } | 541 } |
538 | 542 |
539 bool MessagePumpForGpu::ProcessNextMessage() { | 543 bool MessagePumpForGpu::ProcessNextMessage() { |
540 MSG msg; | 544 MSG msg; |
541 if (!PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) | 545 if (!PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) |
542 return false; | 546 return false; |
543 | 547 |
544 if (msg.message == WM_QUIT) { | 548 if (msg.message == WM_QUIT) { |
545 // Repost the QUIT message so that it will be retrieved by the primary | 549 // Repost the QUIT message so that it will be retrieved by the primary |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 if (!filter || it->handler == filter) { | 732 if (!filter || it->handler == filter) { |
729 *item = *it; | 733 *item = *it; |
730 completed_io_.erase(it); | 734 completed_io_.erase(it); |
731 return true; | 735 return true; |
732 } | 736 } |
733 } | 737 } |
734 return false; | 738 return false; |
735 } | 739 } |
736 | 740 |
737 } // namespace base | 741 } // namespace base |
OLD | NEW |