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

Unified Diff: base/message_loop/message_pump_default.cc

Issue 1154953002: Set minimum Windows wait time to 1 ms in MessagePumpDefault::Run (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing header include. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop/message_pump_default.cc
diff --git a/base/message_loop/message_pump_default.cc b/base/message_loop/message_pump_default.cc
index bb9d8ce9ffc657e53d3104049fcd951cb4406321..daa80d853236a132f880f17de3a382f75f39c5dc 100644
--- a/base/message_loop/message_pump_default.cc
+++ b/base/message_loop/message_pump_default.cc
@@ -4,6 +4,8 @@
#include "base/message_loop/message_pump_default.h"
+#include <algorithm>
+
#include "base/logging.h"
#include "base/threading/thread_restrictions.h"
@@ -52,8 +54,14 @@ void MessagePumpDefault::Run(Delegate* delegate) {
event_.Wait();
} else {
TimeDelta delay = delayed_work_time_ - TimeTicks::Now();
- // If the delay is under 1 ms we need to execute the task right away.
- if (delay.InMilliseconds() >= 1) {
+#if defined(OS_WIN)
+ // If the delay is greater than zero and under 1 ms we need to round up to
+ // 1 ms or else we will end up spinning until it counts down to zero
+ // because sub-ms waits aren't supported on Windows.
+ if (delay > TimeDelta())
+ delay = std::max(delay, TimeDelta::FromMilliseconds(1));
+#endif
+ if (delay > TimeDelta()) {
event_.TimedWait(delay);
} else {
// It looks like delayed_work_time_ indicates a time in the past, so we
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698