summaryrefslogtreecommitdiffstats
path: root/base/message_loop/incoming_task_queue.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/message_loop/incoming_task_queue.cc')
-rw-r--r--base/message_loop/incoming_task_queue.cc36
1 files changed, 26 insertions, 10 deletions
diff --git a/base/message_loop/incoming_task_queue.cc b/base/message_loop/incoming_task_queue.cc
index c1ce939..5e9a461 100644
--- a/base/message_loop/incoming_task_queue.cc
+++ b/base/message_loop/incoming_task_queue.cc
@@ -44,7 +44,8 @@ IncomingTaskQueue::IncomingTaskQueue(MessageLoop* message_loop)
message_loop_(message_loop),
next_sequence_num_(0),
message_loop_scheduled_(false),
- always_schedule_work_(AlwaysNotifyPump(message_loop_->type())) {
+ always_schedule_work_(AlwaysNotifyPump(message_loop_->type())),
+ is_ready_for_scheduling_(false) {
}
bool IncomingTaskQueue::AddToIncomingQueue(
@@ -109,6 +110,15 @@ void IncomingTaskQueue::WillDestroyCurrentMessageLoop() {
message_loop_ = NULL;
}
+void IncomingTaskQueue::StartScheduling() {
+ AutoLock lock(incoming_queue_lock_);
+ DCHECK(!is_ready_for_scheduling_);
+ DCHECK(!message_loop_scheduled_);
+ is_ready_for_scheduling_ = true;
+ if (!incoming_queue_.empty())
+ ScheduleWork();
+}
+
IncomingTaskQueue::~IncomingTaskQueue() {
// Verify that WillDestroyCurrentMessageLoop() has been called.
DCHECK(!message_loop_);
@@ -148,19 +158,25 @@ bool IncomingTaskQueue::PostPendingTask(PendingTask* pending_task) {
incoming_queue_.push(*pending_task);
pending_task->task.Reset();
- if (always_schedule_work_ || (!message_loop_scheduled_ && was_empty)) {
- // Wake up the message loop.
- message_loop_->ScheduleWork();
- // After we've scheduled the message loop, we do not need to do so again
- // until we know it has processed all of the work in our queue and is
- // waiting for more work again. The message loop will always attempt to
- // reload from the incoming queue before waiting again so we clear this flag
- // in ReloadWorkQueue().
- message_loop_scheduled_ = true;
+ if (is_ready_for_scheduling_ &&
+ (always_schedule_work_ || (!message_loop_scheduled_ && was_empty))) {
+ ScheduleWork();
}
return true;
}
+void IncomingTaskQueue::ScheduleWork() {
+ DCHECK(is_ready_for_scheduling_);
+ // Wake up the message loop.
+ message_loop_->ScheduleWork();
+ // After we've scheduled the message loop, we do not need to do so again
+ // until we know it has processed all of the work in our queue and is
+ // waiting for more work again. The message loop will always attempt to
+ // reload from the incoming queue before waiting again so we clear this flag
+ // in ReloadWorkQueue().
+ message_loop_scheduled_ = true;
+}
+
} // namespace internal
} // namespace base