| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/task_scheduler/task_tracker.h" | 5 #include "base/task_scheduler/task_tracker.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 void TaskTracker::Flush() { | 212 void TaskTracker::Flush() { |
| 213 AutoSchedulerLock auto_lock(flush_lock_); | 213 AutoSchedulerLock auto_lock(flush_lock_); |
| 214 while (subtle::NoBarrier_Load(&num_pending_undelayed_tasks_) != 0 && | 214 while (subtle::NoBarrier_Load(&num_pending_undelayed_tasks_) != 0 && |
| 215 !IsShutdownComplete()) { | 215 !IsShutdownComplete()) { |
| 216 flush_cv_->Wait(); | 216 flush_cv_->Wait(); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 bool TaskTracker::WillPostTask(const Task* task) { | 220 bool TaskTracker::WillPostTask(const Task* task) { |
| 221 DCHECK(task); | 221 DCHECK(task); |
| 222 DCHECK_LE(static_cast<int>(task->traits.priority()), |
| 223 static_cast<int>(TaskPriority::HIGHEST)); |
| 222 | 224 |
| 223 if (!BeforePostTask(task->traits.shutdown_behavior())) | 225 if (!BeforePostTask(task->traits.shutdown_behavior())) |
| 224 return false; | 226 return false; |
| 225 | 227 |
| 226 if (task->delayed_run_time.is_null()) | 228 if (task->delayed_run_time.is_null()) |
| 227 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, 1); | 229 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, 1); |
| 228 | 230 |
| 229 debug::TaskAnnotator task_annotator; | 231 debug::TaskAnnotator task_annotator; |
| 230 task_annotator.DidQueueTask(kQueueFunctionName, *task); | 232 task_annotator.DidQueueTask(kQueueFunctionName, *task); |
| 231 | 233 |
| 232 return true; | 234 return true; |
| 233 } | 235 } |
| 234 | 236 |
| 235 bool TaskTracker::RunTask(std::unique_ptr<Task> task, | 237 bool TaskTracker::RunTask(std::unique_ptr<Task> task, |
| 236 const SequenceToken& sequence_token) { | 238 const SequenceToken& sequence_token) { |
| 237 DCHECK(task); | 239 DCHECK(task); |
| 240 DCHECK_LE(static_cast<int>(task->traits.priority()), |
| 241 static_cast<int>(TaskPriority::HIGHEST)); |
| 238 DCHECK(sequence_token.IsValid()); | 242 DCHECK(sequence_token.IsValid()); |
| 239 | 243 |
| 240 const TaskShutdownBehavior shutdown_behavior = | 244 const TaskShutdownBehavior shutdown_behavior = |
| 241 task->traits.shutdown_behavior(); | 245 task->traits.shutdown_behavior(); |
| 242 const bool can_run_task = BeforeRunTask(shutdown_behavior); | 246 const bool can_run_task = BeforeRunTask(shutdown_behavior); |
| 243 const bool is_delayed = !task->delayed_run_time.is_null(); | 247 const bool is_delayed = !task->delayed_run_time.is_null(); |
| 244 | 248 |
| 245 if (can_run_task) { | 249 if (can_run_task) { |
| 246 RecordTaskLatencyHistogram(task.get()); | 250 RecordTaskLatencyHistogram(task.get()); |
| 247 | 251 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 task_latency_histograms_[static_cast<int>(task->traits.priority())] | 497 task_latency_histograms_[static_cast<int>(task->traits.priority())] |
| 494 [task->traits.may_block() || | 498 [task->traits.may_block() || |
| 495 task->traits.with_base_sync_primitives() | 499 task->traits.with_base_sync_primitives() |
| 496 ? 1 | 500 ? 1 |
| 497 : 0] | 501 : 0] |
| 498 ->AddTime(task_latency); | 502 ->AddTime(task_latency); |
| 499 } | 503 } |
| 500 | 504 |
| 501 } // namespace internal | 505 } // namespace internal |
| 502 } // namespace base | 506 } // namespace base |
| OLD | NEW |