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

Unified Diff: mojo/public/cpp/utility/lib/run_loop.cc

Issue 588593002: mojo: Allow basic RunLoop to be quit from a posted task. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor python tests Created 6 years, 3 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
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..25dd236c56abc54ea9b2bededea98c9c74570d41 100644
--- a/mojo/public/cpp/utility/lib/run_loop.cc
+++ b/mojo/public/cpp/utility/lib/run_loop.cc
@@ -93,37 +93,40 @@ 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) {
jamesr 2014/09/24 08:04:32 could we make this a 2-state enum instead of a boo
qsr 2014/09/24 09:14:15 Done.
assert(current() == this);
RunState* old_state = run_state_;
RunState run_state;
run_state_ = &run_state;
- while (!run_state.should_quit) {
- DoDelayedWork();
- if (!Wait(true) && delayed_tasks_.empty())
+ for (;;) {
+ bool did_work = DoDelayedWork();
+ if (run_state.should_quit)
+ break;
+ did_work |= Wait(until_idle);
+ if (run_state.should_quit)
+ break;
+ if (!did_work && until_idle)
break;
}
run_state_ = old_state;
}
-void RunLoop::DoDelayedWork() {
+bool RunLoop::DoDelayedWork() {
MojoTimeTicks now = GetTimeTicksNow();
if (!delayed_tasks_.empty() && delayed_tasks_.top().run_time <= now) {
PendingTask task = delayed_tasks_.top();
delayed_tasks_.pop();
task.task.Run();
+ return true;
}
+ return false;
}
void RunLoop::Quit() {
« no previous file with comments | « no previous file | mojo/public/cpp/utility/run_loop.h » ('j') | mojo/public/cpp/utility/tests/run_loop_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698