Skip to content

Instantly share code, notes, and snippets.

@huangdongxu
Created December 30, 2011 13:57
Show Gist options
  • Save huangdongxu/1539971 to your computer and use it in GitHub Desktop.
Save huangdongxu/1539971 to your computer and use it in GitHub Desktop.
messageloop_dowork.cpp
bool MessageLoop::DoWork() {
if (!nestable_tasks_allowed_) {
// Task can't be executed right now.
return false;
}
for (;;) {
ReloadWorkQueue();
if (work_queue_.empty())
break;
// Execute oldest task.
do {
PendingTask pending_task = work_queue_.front();
work_queue_.pop();
if (!pending_task.delayed_run_time.is_null()) {
AddToDelayedWorkQueue(pending_task);
// If we changed the topmost task, then it is time to reschedule.
if (delayed_work_queue_.top().task.Equals(pending_task.task))
pump_->ScheduleDelayedWork(pending_task.delayed_run_time);
} else {
if (DeferOrRunPendingTask(pending_task))
return true;
}
} while (!work_queue_.empty());
}
// Nothing happened.
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment