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 0fac8b3c9c9adbe7597b59096a30ba2a9ad7e935..d7dbaa7f2738b5b36deff73d9eafeb151c775342 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" |
#include "build/build_config.h" |
@@ -54,7 +56,25 @@ void MessagePumpDefault::Run(Delegate* delegate) { |
} else { |
TimeDelta delay = delayed_work_time_ - TimeTicks::Now(); |
if (delay > TimeDelta()) { |
+#if defined(OS_WIN) |
danakj
2016/06/22 22:26:55
I am wondering about your choice to put this chang
vmiura
2016/06/22 23:25:28
Yeah, would it make sense to use max_time.InMillis
stanisc
2016/06/22 23:39:43
I considered that but wanted to minimize the impac
brucedawson
2016/06/22 23:41:51
That would require evaluating all uses of TimedWai
danakj
2016/06/22 23:52:59
Hm, I guess sometimes people would want to not wai
stanisc
2016/06/23 00:20:33
The behavior of timed wait depends on platform. On
|
+ // crbug.com/487724: on Windows, waiting for less than 1 ms results in |
+ // returning from TimedWait promptly and spinning the loop. |
+ const TimeDelta min_delay = TimeDelta::FromMilliseconds(1); |
danakj
2016/06/22 22:26:55
nit: You could write constexpr instead for even be
stanisc
2016/06/23 21:18:50
Done.
|
+ do { |
+ delay = std::max(delay, min_delay); |
+ if (event_.TimedWait(delay)) |
+ break; |
+ |
+ // TimedWait can time out earlier than the specified |delay| on |
+ // Windows. It doesn't make sense to run the outer loop in that case |
danakj
2016/06/22 23:52:59
What part of this is windows-specific, since Timed
brucedawson
2016/06/23 00:01:12
The Windows wait/sleep functions all take millisec
danakj
2016/06/23 00:02:55
That makes the min_delay windows specific. But wha
|
+ // because there isn't going to be any new work. It is less overhead |
+ // go just go back to wait. |
danakj
2016/06/22 22:26:55
"to just go"
stanisc
2016/06/23 21:18:50
Done.
|
+ // In practice this inner wait loop might have up to 3 iterations. |
+ delay = delayed_work_time_ - TimeTicks::Now(); |
danakj
2016/06/22 22:26:55
IIRC Now() is quite expensive on some windows syst
stanisc
2016/06/22 23:39:43
Good question! If we don't do this inner loop with
brucedawson
2016/06/22 23:41:51
I don't think Now() is ever particularly expensive
danakj
2016/06/22 23:52:59
Interesting, I recall in compositor land we went t
|
+ } while (delay > TimeDelta()); |
+#else |
event_.TimedWait(delay); |
+#endif |
} else { |
// It looks like delayed_work_time_ indicates a time in the past, so we |
// need to call DoDelayedWork now. |