Index: mojo/public/cpp/utility/lib/run_loop.cc |
diff --git a/mojo/public/cpp/utility/lib/run_loop.cc b/mojo/public/cpp/utility/lib/run_loop.cc |
index b06880dc9d6e0a1dbd02aaeb1cb105a9a39bad54..0ec8c23b0efac99b7f570b575a1d065150aeec4f 100644 |
--- a/mojo/public/cpp/utility/lib/run_loop.cc |
+++ b/mojo/public/cpp/utility/lib/run_loop.cc |
@@ -93,25 +93,26 @@ bool RunLoop::HasHandler(const Handle& handle) const { |
} |
void RunLoop::Run() { |
- assert(current() == this); |
- RunState* old_state = run_state_; |
- RunState run_state; |
- run_state_ = &run_state; |
- while (!run_state.should_quit) { |
- DoDelayedWork(); |
- Wait(false); |
- } |
- run_state_ = old_state; |
+ RunInternal(false); |
} |
void RunLoop::RunUntilIdle() { |
+ RunInternal(true); |
+} |
+ |
+void RunLoop::RunInternal(bool until_idle) { |
assert(current() == this); |
RunState* old_state = run_state_; |
RunState run_state; |
run_state_ = &run_state; |
- while (!run_state.should_quit) { |
+ for (;;) { |
DoDelayedWork(); |
- if (!Wait(true) && delayed_tasks_.empty()) |
+ if (run_state.should_quit) |
+ break; |
+ bool did_notify = Wait(until_idle); |
+ if (run_state.should_quit) |
+ break; |
+ if (!did_notify && until_idle && delayed_tasks_.empty()) |
jamesr
2014/09/24 04:23:10
RunUntilIdle does not mean run until the delayed t
|
break; |
} |
run_state_ = old_state; |
@@ -240,7 +241,7 @@ RunLoop::WaitState RunLoop::GetWaitState(bool non_blocking) const { |
else |
min_time = std::min(min_time, delayed_min_time); |
} |
- if (non_blocking) { |
+ if (non_blocking && delayed_tasks_.empty()) { |
wait_state.deadline = static_cast<MojoDeadline>(0); |
} else if (min_time != kInvalidTimeTicks) { |
const MojoTimeTicks now = GetTimeTicksNow(); |