| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 const SequenceToken& sequence_token) { | 213 const SequenceToken& sequence_token) { |
| 214 DCHECK(task); | 214 DCHECK(task); |
| 215 DCHECK(sequence_token.IsValid()); | 215 DCHECK(sequence_token.IsValid()); |
| 216 | 216 |
| 217 const TaskShutdownBehavior shutdown_behavior = | 217 const TaskShutdownBehavior shutdown_behavior = |
| 218 task->traits.shutdown_behavior(); | 218 task->traits.shutdown_behavior(); |
| 219 const bool can_run_task = BeforeRunTask(shutdown_behavior); | 219 const bool can_run_task = BeforeRunTask(shutdown_behavior); |
| 220 const bool is_delayed = !task->delayed_run_time.is_null(); | 220 const bool is_delayed = !task->delayed_run_time.is_null(); |
| 221 | 221 |
| 222 if (can_run_task) { | 222 if (can_run_task) { |
| 223 // All tasks run through here and the scheduler itself doesn't use | 223 const bool previous_singleton_allowed = |
| 224 // singletons. Therefore, it isn't necessary to reset the singleton allowed | 224 ThreadRestrictions::SetSingletonAllowed( |
| 225 // bit after running the task. | 225 task->traits.shutdown_behavior() != |
| 226 ThreadRestrictions::SetSingletonAllowed( | 226 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); |
| 227 task->traits.shutdown_behavior() != | 227 const bool previous_io_allowed = |
| 228 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); | 228 ThreadRestrictions::SetIOAllowed(task->traits.with_file_io()); |
| 229 | |
| 230 const bool previous_wait_allowed = | 229 const bool previous_wait_allowed = |
| 231 ThreadRestrictions::SetWaitAllowed(task->traits.with_wait()); | 230 ThreadRestrictions::SetWaitAllowed(task->traits.with_wait()); |
| 232 | 231 |
| 233 { | 232 { |
| 234 ScopedSetSequenceTokenForCurrentThread | 233 ScopedSetSequenceTokenForCurrentThread |
| 235 scoped_set_sequence_token_for_current_thread(sequence_token); | 234 scoped_set_sequence_token_for_current_thread(sequence_token); |
| 236 ScopedSetTaskPriorityForCurrentThread | 235 ScopedSetTaskPriorityForCurrentThread |
| 237 scoped_set_task_priority_for_current_thread(task->traits.priority()); | 236 scoped_set_task_priority_for_current_thread(task->traits.priority()); |
| 238 | 237 |
| 239 // Set up TaskRunnerHandle as expected for the scope of the task. | 238 // Set up TaskRunnerHandle as expected for the scope of the task. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 260 // to the trace event generated above. This is not possible however until | 259 // to the trace event generated above. This is not possible however until |
| 261 // http://crbug.com/652692 is resolved. | 260 // http://crbug.com/652692 is resolved. |
| 262 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info", | 261 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info", |
| 263 MakeUnique<TaskTracingInfo>(task->traits, execution_mode, | 262 MakeUnique<TaskTracingInfo>(task->traits, execution_mode, |
| 264 sequence_token)); | 263 sequence_token)); |
| 265 | 264 |
| 266 PerformRunTask(std::move(task)); | 265 PerformRunTask(std::move(task)); |
| 267 } | 266 } |
| 268 | 267 |
| 269 ThreadRestrictions::SetWaitAllowed(previous_wait_allowed); | 268 ThreadRestrictions::SetWaitAllowed(previous_wait_allowed); |
| 269 ThreadRestrictions::SetIOAllowed(previous_io_allowed); |
| 270 ThreadRestrictions::SetSingletonAllowed(previous_singleton_allowed); |
| 270 | 271 |
| 271 AfterRunTask(shutdown_behavior); | 272 AfterRunTask(shutdown_behavior); |
| 272 } | 273 } |
| 273 | 274 |
| 274 if (!is_delayed) | 275 if (!is_delayed) |
| 275 DecrementNumPendingUndelayedTasks(); | 276 DecrementNumPendingUndelayedTasks(); |
| 276 | 277 |
| 277 return can_run_task; | 278 return can_run_task; |
| 278 } | 279 } |
| 279 | 280 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); | 450 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); |
| 450 DCHECK_GE(new_num_pending_undelayed_tasks, 0); | 451 DCHECK_GE(new_num_pending_undelayed_tasks, 0); |
| 451 if (new_num_pending_undelayed_tasks == 0) { | 452 if (new_num_pending_undelayed_tasks == 0) { |
| 452 AutoSchedulerLock auto_lock(flush_lock_); | 453 AutoSchedulerLock auto_lock(flush_lock_); |
| 453 flush_cv_->Signal(); | 454 flush_cv_->Signal(); |
| 454 } | 455 } |
| 455 } | 456 } |
| 456 | 457 |
| 457 } // namespace internal | 458 } // namespace internal |
| 458 } // namespace base | 459 } // namespace base |
| OLD | NEW |