OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "platform/scheduler/base/task_queue_impl.h" | 5 #include "platform/scheduler/base/task_queue_impl.h" |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/trace_event/blame_context.h" | 10 #include "base/trace_event/blame_context.h" |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 const tracked_objects::Location& from_here, | 212 const tracked_objects::Location& from_here, |
213 const base::Closure& task, | 213 const base::Closure& task, |
214 TaskType task_type) { | 214 TaskType task_type) { |
215 base::AutoLock lock(any_thread_lock_); | 215 base::AutoLock lock(any_thread_lock_); |
216 if (!any_thread().task_queue_manager) | 216 if (!any_thread().task_queue_manager) |
217 return false; | 217 return false; |
218 | 218 |
219 EnqueueOrder sequence_number = | 219 EnqueueOrder sequence_number = |
220 any_thread().task_queue_manager->GetNextSequenceNumber(); | 220 any_thread().task_queue_manager->GetNextSequenceNumber(); |
221 | 221 |
222 PushOntoImmediateIncomingQueueLocked( | 222 PushOntoImmediateIncomingQueueLocked(from_here, task, base::TimeTicks(), |
223 from_here, | 223 sequence_number, |
224 task, | 224 task_type != TaskType::NON_NESTABLE); |
225 base::TimeTicks(), | |
226 sequence_number, | |
227 task_type != TaskType::NON_NESTABLE); | |
228 return true; | 225 return true; |
229 } | 226 } |
230 | 227 |
231 bool TaskQueueImpl::PostDelayedTaskImpl( | 228 bool TaskQueueImpl::PostDelayedTaskImpl( |
232 const tracked_objects::Location& from_here, | 229 const tracked_objects::Location& from_here, |
233 const base::Closure& task, | 230 const base::Closure& task, |
234 base::TimeDelta delay, | 231 base::TimeDelta delay, |
235 TaskType task_type) { | 232 TaskType task_type) { |
236 DCHECK_GT(delay, base::TimeDelta()); | 233 DCHECK_GT(delay, base::TimeDelta()); |
237 if (base::PlatformThread::CurrentId() == thread_id_) { | 234 if (base::PlatformThread::CurrentId() == thread_id_) { |
(...skipping 25 matching lines...) Expand all Loading... |
263 base::TimeTicks time_domain_now = any_thread().time_domain->Now(); | 260 base::TimeTicks time_domain_now = any_thread().time_domain->Now(); |
264 base::TimeTicks time_domain_delayed_run_time = time_domain_now + delay; | 261 base::TimeTicks time_domain_delayed_run_time = time_domain_now + delay; |
265 PushOntoDelayedIncomingQueueLocked( | 262 PushOntoDelayedIncomingQueueLocked( |
266 Task(from_here, task, time_domain_delayed_run_time, sequence_number, | 263 Task(from_here, task, time_domain_delayed_run_time, sequence_number, |
267 task_type != TaskType::NON_NESTABLE)); | 264 task_type != TaskType::NON_NESTABLE)); |
268 } | 265 } |
269 return true; | 266 return true; |
270 } | 267 } |
271 | 268 |
272 void TaskQueueImpl::PushOntoDelayedIncomingQueueFromMainThread( | 269 void TaskQueueImpl::PushOntoDelayedIncomingQueueFromMainThread( |
273 Task pending_task, base::TimeTicks now) { | 270 Task pending_task, |
| 271 base::TimeTicks now) { |
274 base::TimeTicks delayed_run_time = pending_task.delayed_run_time; | 272 base::TimeTicks delayed_run_time = pending_task.delayed_run_time; |
275 main_thread_only().task_queue_manager->DidQueueTask(pending_task); | 273 main_thread_only().task_queue_manager->DidQueueTask(pending_task); |
276 main_thread_only().delayed_incoming_queue.push(std::move(pending_task)); | 274 main_thread_only().delayed_incoming_queue.push(std::move(pending_task)); |
277 | 275 |
278 // If |pending_task| is at the head of the queue, then make sure a wakeup | 276 // If |pending_task| is at the head of the queue, then make sure a wakeup |
279 // is requested if the queue is enabled. Note we still want to schedule a | 277 // is requested if the queue is enabled. Note we still want to schedule a |
280 // wakeup even if blocked by a fence, because we'd break throttling logic | 278 // wakeup even if blocked by a fence, because we'd break throttling logic |
281 // otherwise. | 279 // otherwise. |
282 base::TimeTicks next_delayed_task = | 280 base::TimeTicks next_delayed_task = |
283 main_thread_only().delayed_incoming_queue.top().delayed_run_time; | 281 main_thread_only().delayed_incoming_queue.top().delayed_run_time; |
284 if (next_delayed_task == delayed_run_time && IsQueueEnabled()) { | 282 if (next_delayed_task == delayed_run_time && IsQueueEnabled()) { |
285 main_thread_only().time_domain->ScheduleDelayedWork(this, delayed_run_time, | 283 main_thread_only().time_domain->ScheduleDelayedWork(this, delayed_run_time, |
286 now); | 284 now); |
287 } | 285 } |
288 | 286 |
289 TraceQueueSize(false); | 287 TraceQueueSize(false); |
290 } | 288 } |
291 | 289 |
292 void TaskQueueImpl::PushOntoDelayedIncomingQueueLocked(Task pending_task) { | 290 void TaskQueueImpl::PushOntoDelayedIncomingQueueLocked(Task pending_task) { |
293 any_thread().task_queue_manager->DidQueueTask(pending_task); | 291 any_thread().task_queue_manager->DidQueueTask(pending_task); |
294 | 292 |
295 int thread_hop_task_sequence_number = | 293 int thread_hop_task_sequence_number = |
296 any_thread().task_queue_manager->GetNextSequenceNumber(); | 294 any_thread().task_queue_manager->GetNextSequenceNumber(); |
297 PushOntoImmediateIncomingQueueLocked( | 295 PushOntoImmediateIncomingQueueLocked( |
298 FROM_HERE, | 296 FROM_HERE, base::Bind(&TaskQueueImpl::ScheduleDelayedWorkTask, this, |
299 base::Bind(&TaskQueueImpl::ScheduleDelayedWorkTask, this, | 297 base::Passed(&pending_task)), |
300 base::Passed(&pending_task)), | 298 base::TimeTicks(), thread_hop_task_sequence_number, false); |
301 base::TimeTicks(), | |
302 thread_hop_task_sequence_number, | |
303 false); | |
304 } | 299 } |
305 | 300 |
306 void TaskQueueImpl::ScheduleDelayedWorkTask(Task pending_task) { | 301 void TaskQueueImpl::ScheduleDelayedWorkTask(Task pending_task) { |
307 DCHECK(main_thread_checker_.CalledOnValidThread()); | 302 DCHECK(main_thread_checker_.CalledOnValidThread()); |
308 base::TimeTicks delayed_run_time = pending_task.delayed_run_time; | 303 base::TimeTicks delayed_run_time = pending_task.delayed_run_time; |
309 base::TimeTicks time_domain_now = main_thread_only().time_domain->Now(); | 304 base::TimeTicks time_domain_now = main_thread_only().time_domain->Now(); |
310 if (delayed_run_time <= time_domain_now) { | 305 if (delayed_run_time <= time_domain_now) { |
311 // If |delayed_run_time| is in the past then push it onto the work queue | 306 // If |delayed_run_time| is in the past then push it onto the work queue |
312 // immediately. To ensure the right task ordering we need to temporarily | 307 // immediately. To ensure the right task ordering we need to temporarily |
313 // push it onto the |delayed_incoming_queue|. | 308 // push it onto the |delayed_incoming_queue|. |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 | 853 |
859 void TaskQueueImpl::PushImmediateIncomingTaskForTest( | 854 void TaskQueueImpl::PushImmediateIncomingTaskForTest( |
860 TaskQueueImpl::Task&& task) { | 855 TaskQueueImpl::Task&& task) { |
861 base::AutoLock lock(any_thread_lock_); | 856 base::AutoLock lock(any_thread_lock_); |
862 any_thread().immediate_incoming_queue.push_back(std::move(task)); | 857 any_thread().immediate_incoming_queue.push_back(std::move(task)); |
863 } | 858 } |
864 | 859 |
865 } // namespace internal | 860 } // namespace internal |
866 } // namespace scheduler | 861 } // namespace scheduler |
867 } // namespace blink | 862 } // namespace blink |
OLD | NEW |