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 "components/scheduler/base/task_queue_impl.h" | 5 #include "components/scheduler/base/task_queue_impl.h" |
6 | 6 |
7 #include "base/trace_event/blame_context.h" | 7 #include "base/trace_event/blame_context.h" |
8 #include "components/scheduler/base/task_queue_manager.h" | 8 #include "components/scheduler/base/task_queue_manager.h" |
9 #include "components/scheduler/base/task_queue_manager_delegate.h" | 9 #include "components/scheduler/base/task_queue_manager_delegate.h" |
10 #include "components/scheduler/base/time_domain.h" | 10 #include "components/scheduler/base/time_domain.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 DCHECK_GT(delay, base::TimeDelta()); | 182 DCHECK_GT(delay, base::TimeDelta()); |
183 if (base::PlatformThread::CurrentId() == thread_id_) { | 183 if (base::PlatformThread::CurrentId() == thread_id_) { |
184 // Lock-free fast path for delayed tasks posted from the main thread. | 184 // Lock-free fast path for delayed tasks posted from the main thread. |
185 if (!main_thread_only().task_queue_manager) | 185 if (!main_thread_only().task_queue_manager) |
186 return false; | 186 return false; |
187 | 187 |
188 EnqueueOrder sequence_number = | 188 EnqueueOrder sequence_number = |
189 main_thread_only().task_queue_manager->GetNextSequenceNumber(); | 189 main_thread_only().task_queue_manager->GetNextSequenceNumber(); |
190 | 190 |
191 base::TimeTicks time_domain_now = main_thread_only().time_domain->Now(); | 191 base::TimeTicks time_domain_now = main_thread_only().time_domain->Now(); |
192 base::TimeTicks time_domain_delayed_run_time = | 192 base::TimeTicks time_domain_delayed_run_time = time_domain_now + delay; |
193 main_thread_only().time_domain->ComputeDelayedRunTime(time_domain_now, | |
194 delay); | |
195 PushOntoDelayedIncomingQueueFromMainThread( | 193 PushOntoDelayedIncomingQueueFromMainThread( |
196 Task(from_here, task, time_domain_delayed_run_time, sequence_number, | 194 Task(from_here, task, time_domain_delayed_run_time, sequence_number, |
197 task_type != TaskType::NON_NESTABLE), | 195 task_type != TaskType::NON_NESTABLE), |
198 time_domain_now); | 196 time_domain_now); |
199 } else { | 197 } else { |
200 // NOTE posting a delayed task from a different thread is not expected to | 198 // NOTE posting a delayed task from a different thread is not expected to |
201 // be common. This pathway is less optimal than perhaps it could be | 199 // be common. This pathway is less optimal than perhaps it could be |
202 // because it causes two main thread tasks to be run. Should this | 200 // because it causes two main thread tasks to be run. Should this |
203 // assumption prove to be false in future, we may need to revisit this. | 201 // assumption prove to be false in future, we may need to revisit this. |
204 base::AutoLock lock(any_thread_lock_); | 202 base::AutoLock lock(any_thread_lock_); |
205 if (!any_thread().task_queue_manager) | 203 if (!any_thread().task_queue_manager) |
206 return false; | 204 return false; |
207 | 205 |
208 EnqueueOrder sequence_number = | 206 EnqueueOrder sequence_number = |
209 any_thread().task_queue_manager->GetNextSequenceNumber(); | 207 any_thread().task_queue_manager->GetNextSequenceNumber(); |
210 | 208 |
211 base::TimeTicks time_domain_now = any_thread().time_domain->Now(); | 209 base::TimeTicks time_domain_now = any_thread().time_domain->Now(); |
212 base::TimeTicks time_domain_delayed_run_time = | 210 base::TimeTicks time_domain_delayed_run_time = time_domain_now + delay; |
213 any_thread().time_domain->ComputeDelayedRunTime(time_domain_now, delay); | |
214 PushOntoDelayedIncomingQueueLocked( | 211 PushOntoDelayedIncomingQueueLocked( |
215 Task(from_here, task, time_domain_delayed_run_time, sequence_number, | 212 Task(from_here, task, time_domain_delayed_run_time, sequence_number, |
216 task_type != TaskType::NON_NESTABLE)); | 213 task_type != TaskType::NON_NESTABLE)); |
217 } | 214 } |
218 return true; | 215 return true; |
219 } | 216 } |
220 | 217 |
221 void TaskQueueImpl::PushOntoDelayedIncomingQueueFromMainThread( | 218 void TaskQueueImpl::PushOntoDelayedIncomingQueueFromMainThread( |
222 Task pending_task, | 219 Task pending_task, |
223 base::TimeTicks now) { | 220 base::TimeTicks now) { |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 state->SetBoolean("nestable", task.nestable); | 708 state->SetBoolean("nestable", task.nestable); |
712 state->SetBoolean("is_high_res", task.is_high_res); | 709 state->SetBoolean("is_high_res", task.is_high_res); |
713 state->SetDouble( | 710 state->SetDouble( |
714 "delayed_run_time", | 711 "delayed_run_time", |
715 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); | 712 (task.delayed_run_time - base::TimeTicks()).InMicroseconds() / 1000.0L); |
716 state->EndDictionary(); | 713 state->EndDictionary(); |
717 } | 714 } |
718 | 715 |
719 } // namespace internal | 716 } // namespace internal |
720 } // namespace scheduler | 717 } // namespace scheduler |
OLD | NEW |