OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_pump_win.h" | 5 #include "base/message_pump_win.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include "base/histogram.h" | 9 #include "base/histogram.h" |
10 #include "base/win_util.h" | 10 #include "base/win_util.h" |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 // then resets the have_work_ flag (allowing a replacement kMsgHaveWork to | 373 // then resets the have_work_ flag (allowing a replacement kMsgHaveWork to |
374 // possibly be posted), and finally dispatches that peeked replacement. Note | 374 // possibly be posted), and finally dispatches that peeked replacement. Note |
375 // that the re-post of kMsgHaveWork may be asynchronous to this thread!! | 375 // that the re-post of kMsgHaveWork may be asynchronous to this thread!! |
376 | 376 |
377 MSG msg; | 377 MSG msg; |
378 bool have_message = (0 != PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)); | 378 bool have_message = (0 != PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)); |
379 DCHECK(!have_message || kMsgHaveWork != msg.message || | 379 DCHECK(!have_message || kMsgHaveWork != msg.message || |
380 msg.hwnd != message_hwnd_); | 380 msg.hwnd != message_hwnd_); |
381 | 381 |
382 // Since we discarded a kMsgHaveWork message, we must update the flag. | 382 // Since we discarded a kMsgHaveWork message, we must update the flag. |
383 int old_have_work = InterlockedExchange(&have_work_, 0); | 383 InterlockedExchange(&have_work_, 0); |
384 DCHECK(old_have_work); | |
385 | 384 |
386 // We don't need a special time slice if we didn't have_message to process. | 385 // TODO(darin,jar): There is risk of being lost in a sub-pump within the call |
387 if (!have_message) | 386 // to ProcessMessageHelper, which could result in no longer getting a |
388 return false; | 387 // kMsgHaveWork message until the next out-of-band call to ScheduleWork. |
389 | 388 |
390 // Guarantee we'll get another time slice in the case where we go into native | 389 return have_message && ProcessMessageHelper(msg); |
391 // windows code. This ScheduleWork() may hurt performance a tiny bit when | |
392 // tasks appear very infrequently, but when the event queue is busy, the | |
393 // kMsgHaveWork events get (percentage wise) rarer and rarer. | |
394 ScheduleWork(); | |
395 return ProcessMessageHelper(msg); | |
396 } | 390 } |
397 | 391 |
398 //----------------------------------------------------------------------------- | 392 //----------------------------------------------------------------------------- |
399 // MessagePumpForIO public: | 393 // MessagePumpForIO public: |
400 | 394 |
401 MessagePumpForIO::MessagePumpForIO() { | 395 MessagePumpForIO::MessagePumpForIO() { |
402 port_.Set(CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 1)); | 396 port_.Set(CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, NULL, 1)); |
403 DCHECK(port_.IsValid()); | 397 DCHECK(port_.IsValid()); |
404 } | 398 } |
405 | 399 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 if (!filter || it->handler == filter) { | 541 if (!filter || it->handler == filter) { |
548 *item = *it; | 542 *item = *it; |
549 completed_io_.erase(it); | 543 completed_io_.erase(it); |
550 return true; | 544 return true; |
551 } | 545 } |
552 } | 546 } |
553 return false; | 547 return false; |
554 } | 548 } |
555 | 549 |
556 } // namespace base | 550 } // namespace base |
OLD | NEW |