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

Side by Side Diff: base/message_loop/message_pump_win.cc

Issue 395913006: High resolution timer fix for Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more cleanup Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 DCHECK(message_hwnd_); 262 DCHECK(message_hwnd_);
263 } 263 }
264 264
265 void MessagePumpForUI::WaitForWork() { 265 void MessagePumpForUI::WaitForWork() {
266 // Wait until a message is available, up to the time needed by the timer 266 // Wait until a message is available, up to the time needed by the timer
267 // manager to fire the next set of timers. 267 // manager to fire the next set of timers.
268 int delay = GetCurrentDelay(); 268 int delay = GetCurrentDelay();
269 if (delay < 0) // Negative value means no timers waiting. 269 if (delay < 0) // Negative value means no timers waiting.
270 delay = INFINITE; 270 delay = INFINITE;
271 271
272 // The delegate will crank the systemwide timer resolution if needed.
273 // Note that the |delay| value is not enough of an indicator if we need to
274 // to so. For example, imagine a 30 seconds delayed task that we only get
275 // arround to service 5ms before the deadline. Should we crank up the
276 // systemwide timer? no. A 30s timer can be fired 15ms later.
277 state_->delegate->UpdateTimerGranularity();
278
272 DWORD result; 279 DWORD result;
273 result = MsgWaitForMultipleObjectsEx(0, NULL, delay, QS_ALLINPUT, 280 result = MsgWaitForMultipleObjectsEx(0, NULL, delay, QS_ALLINPUT,
274 MWMO_INPUTAVAILABLE); 281 MWMO_INPUTAVAILABLE);
275 282
276 if (WAIT_OBJECT_0 == result) { 283 if (WAIT_OBJECT_0 == result) {
277 // A WM_* message is available. 284 // A WM_* message is available.
278 // If a parent child relationship exists between windows across threads 285 // If a parent child relationship exists between windows across threads
279 // then their thread inputs are implicitly attached. 286 // then their thread inputs are implicitly attached.
280 // This causes the MsgWaitForMultipleObjectsEx API to return indicating 287 // This causes the MsgWaitForMultipleObjectsEx API to return indicating
281 // that messages are ready for processing (Specifically, mouse messages 288 // that messages are ready for processing (Specifically, mouse messages
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 529 }
523 } 530 }
524 531
525 // Wait until IO completes, up to the time needed by the timer manager to fire 532 // Wait until IO completes, up to the time needed by the timer manager to fire
526 // the next set of timers. 533 // the next set of timers.
527 void MessagePumpForIO::WaitForWork() { 534 void MessagePumpForIO::WaitForWork() {
528 // We do not support nested IO message loops. This is to avoid messy 535 // We do not support nested IO message loops. This is to avoid messy
529 // recursion problems. 536 // recursion problems.
530 DCHECK_EQ(1, state_->run_depth) << "Cannot nest an IO message loop!"; 537 DCHECK_EQ(1, state_->run_depth) << "Cannot nest an IO message loop!";
531 538
539 // See the comment in MessagePumpForUI::WaitForWork().
540 state_->delegate->UpdateTimerGranularity();
541
532 int timeout = GetCurrentDelay(); 542 int timeout = GetCurrentDelay();
533 if (timeout < 0) // Negative value means no timers waiting. 543 if (timeout < 0) // Negative value means no timers waiting.
534 timeout = INFINITE; 544 timeout = INFINITE;
535 545
536 WaitForIOCompletion(timeout, NULL); 546 WaitForIOCompletion(timeout, NULL);
537 } 547 }
538 548
539 bool MessagePumpForIO::WaitForIOCompletion(DWORD timeout, IOHandler* filter) { 549 bool MessagePumpForIO::WaitForIOCompletion(DWORD timeout, IOHandler* filter) {
540 IOItem item; 550 IOItem item;
541 if (completed_io_.empty() || !MatchCompletedIOItem(filter, &item)) { 551 if (completed_io_.empty() || !MatchCompletedIOItem(filter, &item)) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 656
647 // static 657 // static
648 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler( 658 MessagePumpForIO::IOHandler* MessagePumpForIO::KeyToHandler(
649 ULONG_PTR key, 659 ULONG_PTR key,
650 bool* has_valid_io_context) { 660 bool* has_valid_io_context) {
651 *has_valid_io_context = ((key & 1) == 0); 661 *has_valid_io_context = ((key & 1) == 0);
652 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1)); 662 return reinterpret_cast<IOHandler*>(key & ~static_cast<ULONG_PTR>(1));
653 } 663 }
654 664
655 } // namespace base 665 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698