Commit 990d0c7d authored by ananta's avatar ananta Committed by Commit bot

Treat a delay of under 1 millisecond in MessagePumpDefault as a signal that...

Treat a delay of under 1 millisecond in MessagePumpDefault as a signal that the corresponding delayed task needs to execute

On Windows for e.g. the lowest resolution we can get on the system clock is 1 ms or 4 ms depending on whether the machine
is powered by AC or battery. The OS default is 15ms. So that effectively means that if a delayed task is waiting to execute
for a delay of under 1 ms would cause the underlying OS WaitForSingleObject call to return immediately effectively spinning
a tight loop with a kernel mode context switch.

Fix is to treat a delay of under 1 ms as a signal that the task is ready to execute for all platforms.

BUG=487724

Review URL: https://codereview.chromium.org/1137453006

Cr-Commit-Position: refs/heads/master@{#329997}
parent 3619e48e
......@@ -52,7 +52,8 @@ void MessagePumpDefault::Run(Delegate* delegate) {
event_.Wait();
} else {
TimeDelta delay = delayed_work_time_ - TimeTicks::Now();
if (delay > TimeDelta()) {
// If the delay is under 1 ms we need to execute the task right away.
if (delay.InMilliseconds() >= 1) {
event_.TimedWait(delay);
} else {
// It looks like delayed_work_time_ indicates a time in the past, so we
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment