OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/message_loop/incoming_task_queue.h" | 5 #include "base/message_loop/incoming_task_queue.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 int high_res_tasks = high_res_task_count_; | 102 int high_res_tasks = high_res_task_count_; |
103 high_res_task_count_ = 0; | 103 high_res_task_count_ = 0; |
104 return high_res_tasks; | 104 return high_res_tasks; |
105 } | 105 } |
106 | 106 |
107 void IncomingTaskQueue::WillDestroyCurrentMessageLoop() { | 107 void IncomingTaskQueue::WillDestroyCurrentMessageLoop() { |
108 AutoLock lock(incoming_queue_lock_); | 108 AutoLock lock(incoming_queue_lock_); |
109 message_loop_ = NULL; | 109 message_loop_ = NULL; |
110 } | 110 } |
111 | 111 |
112 void IncomingTaskQueue::StartScheduling() { | |
113 AutoLock lock(incoming_queue_lock_); | |
114 DCHECK(!is_ready_for_scheduling_); | |
Nico
2015/04/24 21:31:15
DCHECK(!message_loop_scheduled_) (…right?)
kinuko
2015/04/27 16:36:04
Done.
| |
115 is_ready_for_scheduling_ = true; | |
danakj
2015/04/24 20:54:39
Can you DCHECK !message_loop_scheduled_ here?
kinuko
2015/04/27 16:36:04
Done.
| |
116 if (!incoming_queue_.empty()) { | |
117 message_loop_->ScheduleWork(); | |
118 message_loop_scheduled_ = true; | |
119 } | |
120 } | |
121 | |
122 bool IncomingTaskQueue::empty() { | |
123 AutoLock lock(incoming_queue_lock_); | |
124 return incoming_queue_.empty(); | |
125 } | |
126 | |
112 IncomingTaskQueue::~IncomingTaskQueue() { | 127 IncomingTaskQueue::~IncomingTaskQueue() { |
113 // Verify that WillDestroyCurrentMessageLoop() has been called. | 128 // Verify that WillDestroyCurrentMessageLoop() has been called. |
114 DCHECK(!message_loop_); | 129 DCHECK(!message_loop_); |
115 } | 130 } |
116 | 131 |
117 TimeTicks IncomingTaskQueue::CalculateDelayedRuntime(TimeDelta delay) { | 132 TimeTicks IncomingTaskQueue::CalculateDelayedRuntime(TimeDelta delay) { |
118 TimeTicks delayed_run_time; | 133 TimeTicks delayed_run_time; |
119 if (delay > TimeDelta()) | 134 if (delay > TimeDelta()) |
120 delayed_run_time = TimeTicks::Now() + delay; | 135 delayed_run_time = TimeTicks::Now() + delay; |
121 else | 136 else |
(...skipping 19 matching lines...) Expand all Loading... | |
141 // delayed_run_time value) and for identifying the task in about:tracing. | 156 // delayed_run_time value) and for identifying the task in about:tracing. |
142 pending_task->sequence_num = next_sequence_num_++; | 157 pending_task->sequence_num = next_sequence_num_++; |
143 | 158 |
144 message_loop_->task_annotator()->DidQueueTask("MessageLoop::PostTask", | 159 message_loop_->task_annotator()->DidQueueTask("MessageLoop::PostTask", |
145 *pending_task); | 160 *pending_task); |
146 | 161 |
147 bool was_empty = incoming_queue_.empty(); | 162 bool was_empty = incoming_queue_.empty(); |
148 incoming_queue_.push(*pending_task); | 163 incoming_queue_.push(*pending_task); |
149 pending_task->task.Reset(); | 164 pending_task->task.Reset(); |
150 | 165 |
151 if (always_schedule_work_ || (!message_loop_scheduled_ && was_empty)) { | 166 if (is_ready_for_scheduling_ && |
167 (always_schedule_work_ || (!message_loop_scheduled_ && was_empty))) { | |
152 // Wake up the message loop. | 168 // Wake up the message loop. |
danakj
2015/04/24 20:54:39
Can you break this into a helper method so you can
kinuko
2015/04/27 16:36:04
Done.
| |
153 message_loop_->ScheduleWork(); | 169 message_loop_->ScheduleWork(); |
154 // After we've scheduled the message loop, we do not need to do so again | 170 // After we've scheduled the message loop, we do not need to do so again |
155 // until we know it has processed all of the work in our queue and is | 171 // until we know it has processed all of the work in our queue and is |
156 // waiting for more work again. The message loop will always attempt to | 172 // waiting for more work again. The message loop will always attempt to |
157 // reload from the incoming queue before waiting again so we clear this flag | 173 // reload from the incoming queue before waiting again so we clear this flag |
158 // in ReloadWorkQueue(). | 174 // in ReloadWorkQueue(). |
159 message_loop_scheduled_ = true; | 175 message_loop_scheduled_ = true; |
160 } | 176 } |
161 | 177 |
162 return true; | 178 return true; |
163 } | 179 } |
164 | 180 |
165 } // namespace internal | 181 } // namespace internal |
166 } // namespace base | 182 } // namespace base |
OLD | NEW |