Chromium Code Reviews| 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 | 8 | 
| 9 #include "base/callback.h" | 9 #include "base/callback.h" | 
| 10 #include "base/debug/task_annotator.h" | 10 #include "base/debug/task_annotator.h" | 
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 const SequenceToken& sequence_token) { | 212 const SequenceToken& sequence_token) { | 
| 213 DCHECK(task); | 213 DCHECK(task); | 
| 214 DCHECK(sequence_token.IsValid()); | 214 DCHECK(sequence_token.IsValid()); | 
| 215 | 215 | 
| 216 const TaskShutdownBehavior shutdown_behavior = | 216 const TaskShutdownBehavior shutdown_behavior = | 
| 217 task->traits.shutdown_behavior(); | 217 task->traits.shutdown_behavior(); | 
| 218 const bool can_run_task = BeforeRunTask(shutdown_behavior); | 218 const bool can_run_task = BeforeRunTask(shutdown_behavior); | 
| 219 const bool is_delayed = !task->delayed_run_time.is_null(); | 219 const bool is_delayed = !task->delayed_run_time.is_null(); | 
| 220 | 220 | 
| 221 if (can_run_task) { | 221 if (can_run_task) { | 
| 222 // All tasks run through here and the scheduler itself doesn't use | 222 const bool previous_singleton_allowed = | 
| 223 // singletons. Therefore, it isn't necessary to reset the singleton allowed | 223 ThreadRestrictions::SetSingletonAllowed( | 
| 224 // bit after running the task. | 224 task->traits.shutdown_behavior() != | 
| 225 ThreadRestrictions::SetSingletonAllowed( | 225 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); | 
| 226 task->traits.shutdown_behavior() != | 226 const bool previous_io_allowed = | 
| 227 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); | 227 ThreadRestrictions::SetIOAllowed(task->traits.with_file_io()); | 
| 228 | 228 | 
| 229 { | 229 { | 
| 230 // Set up SequenceToken as expected for the scope of the task. | 230 // Set up SequenceToken as expected for the scope of the task. | 
| 231 ScopedSetSequenceTokenForCurrentThread | 231 ScopedSetSequenceTokenForCurrentThread | 
| 232 scoped_set_sequence_token_for_current_thread(sequence_token); | 232 scoped_set_sequence_token_for_current_thread(sequence_token); | 
| 233 | 233 | 
| 234 // Set up TaskRunnerHandle as expected for the scope of the task. | 234 // Set up TaskRunnerHandle as expected for the scope of the task. | 
| 235 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle; | 235 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle; | 
| 236 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle; | 236 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle; | 
| 237 DCHECK(!task->sequenced_task_runner_ref || | 237 DCHECK(!task->sequenced_task_runner_ref || | 
| (...skipping 16 matching lines...) Expand all Loading... | |
| 254 // TODO(gab): In a better world this would be tacked on as an extra arg | 254 // TODO(gab): In a better world this would be tacked on as an extra arg | 
| 255 // to the trace event generated above. This is not possible however until | 255 // to the trace event generated above. This is not possible however until | 
| 256 // http://crbug.com/652692 is resolved. | 256 // http://crbug.com/652692 is resolved. | 
| 257 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info", | 257 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info", | 
| 258 MakeUnique<TaskTracingInfo>(task->traits, execution_mode, | 258 MakeUnique<TaskTracingInfo>(task->traits, execution_mode, | 
| 259 sequence_token)); | 259 sequence_token)); | 
| 260 | 260 | 
| 261 PerformRunTask(std::move(task)); | 261 PerformRunTask(std::move(task)); | 
| 262 } | 262 } | 
| 263 | 263 | 
| 264 ThreadRestrictions::SetSingletonAllowed(previous_singleton_allowed); | |
| 
 
robliao
2016/11/28 22:17:41
I presume this will change with the other CL that
 
fdoray
2016/11/28 22:36:15
Done. Reordered in this CL.
 
 | |
| 265 ThreadRestrictions::SetIOAllowed(previous_io_allowed); | |
| 266 | |
| 264 AfterRunTask(shutdown_behavior); | 267 AfterRunTask(shutdown_behavior); | 
| 265 } | 268 } | 
| 266 | 269 | 
| 267 if (!is_delayed) | 270 if (!is_delayed) | 
| 268 DecrementNumPendingUndelayedTasks(); | 271 DecrementNumPendingUndelayedTasks(); | 
| 269 | 272 | 
| 270 return can_run_task; | 273 return can_run_task; | 
| 271 } | 274 } | 
| 272 | 275 | 
| 273 bool TaskTracker::HasShutdownStarted() const { | 276 bool TaskTracker::HasShutdownStarted() const { | 
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); | 445 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); | 
| 443 DCHECK_GE(new_num_pending_undelayed_tasks, 0); | 446 DCHECK_GE(new_num_pending_undelayed_tasks, 0); | 
| 444 if (new_num_pending_undelayed_tasks == 0) { | 447 if (new_num_pending_undelayed_tasks == 0) { | 
| 445 AutoSchedulerLock auto_lock(flush_lock_); | 448 AutoSchedulerLock auto_lock(flush_lock_); | 
| 446 flush_cv_->Signal(); | 449 flush_cv_->Signal(); | 
| 447 } | 450 } | 
| 448 } | 451 } | 
| 449 | 452 | 
| 450 } // namespace internal | 453 } // namespace internal | 
| 451 } // namespace base | 454 } // namespace base | 
| OLD | NEW |