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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 void MessagePumpForUI::ScheduleWork() { | 99 void MessagePumpForUI::ScheduleWork() { |
100 if (InterlockedExchange(&work_state_, HAVE_WORK) != READY) | 100 if (InterlockedExchange(&work_state_, HAVE_WORK) != READY) |
101 return; // Someone else continued the pumping. | 101 return; // Someone else continued the pumping. |
102 | 102 |
103 // Make sure the MessagePump does some work for us. | 103 // Make sure the MessagePump does some work for us. |
104 BOOL ret = PostMessage(message_window_.hwnd(), kMsgHaveWork, 0, 0); | 104 BOOL ret = PostMessage(message_window_.hwnd(), kMsgHaveWork, 0, 0); |
105 if (ret) | 105 if (ret) |
106 return; // There was room in the Window Message queue. | 106 return; // There was room in the Window Message queue. |
107 | 107 |
108 // We have failed to insert a have-work message, so there is a chance that we | 108 // We have failed to insert a have-work message, so there is a chance that we |
109 // will starve tasks/timers while sitting in a nested message loop. Nested | 109 // will starve tasks/timers while sitting in a nested run loop. Nested |
110 // loops only look at Windows Message queues, and don't look at *our* task | 110 // loops only look at Windows Message queues, and don't look at *our* task |
111 // queues, etc., so we might not get a time slice in such. :-( | 111 // queues, etc., so we might not get a time slice in such. :-( |
112 // We could abort here, but the fear is that this failure mode is plausibly | 112 // We could abort here, but the fear is that this failure mode is plausibly |
113 // common (queue is full, of about 2000 messages), so we'll do a near-graceful | 113 // common (queue is full, of about 2000 messages), so we'll do a near-graceful |
114 // recovery. Nested loops are pretty transient (we think), so this will | 114 // recovery. Nested loops are pretty transient (we think), so this will |
115 // probably be recoverable. | 115 // probably be recoverable. |
116 | 116 |
117 // Clarify that we didn't really insert. | 117 // Clarify that we didn't really insert. |
118 InterlockedExchange(&work_state_, READY); | 118 InterlockedExchange(&work_state_, READY); |
119 UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", MESSAGE_POST_ERROR, | 119 UMA_HISTOGRAM_ENUMERATION("Chrome.MessageLoopProblem", MESSAGE_POST_ERROR, |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 if (!filter || it->handler == filter) { | 571 if (!filter || it->handler == filter) { |
572 *item = *it; | 572 *item = *it; |
573 completed_io_.erase(it); | 573 completed_io_.erase(it); |
574 return true; | 574 return true; |
575 } | 575 } |
576 } | 576 } |
577 return false; | 577 return false; |
578 } | 578 } |
579 | 579 |
580 } // namespace base | 580 } // namespace base |
OLD | NEW |