| 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // All tasks run through here and the scheduler itself doesn't use |
| 223 // singletons. Therefore, it isn't necessary to reset the singleton allowed | 223 // singletons. Therefore, it isn't necessary to reset the singleton allowed |
| 224 // bit after running the task. | 224 // bit after running the task. |
| 225 ThreadRestrictions::SetSingletonAllowed( | 225 ThreadRestrictions::SetSingletonAllowed( |
| 226 task->traits.shutdown_behavior() != | 226 task->traits.shutdown_behavior() != |
| 227 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); | 227 TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN); |
| 228 | 228 |
| 229 const bool previous_wait_allowed = |
| 230 ThreadRestrictions::SetWaitAllowed(task->traits.with_wait()); |
| 231 |
| 229 { | 232 { |
| 230 // Set up SequenceToken as expected for the scope of the task. | 233 // Set up SequenceToken as expected for the scope of the task. |
| 231 ScopedSetSequenceTokenForCurrentThread | 234 ScopedSetSequenceTokenForCurrentThread |
| 232 scoped_set_sequence_token_for_current_thread(sequence_token); | 235 scoped_set_sequence_token_for_current_thread(sequence_token); |
| 233 | 236 |
| 234 // Set up TaskRunnerHandle as expected for the scope of the task. | 237 // Set up TaskRunnerHandle as expected for the scope of the task. |
| 235 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle; | 238 std::unique_ptr<SequencedTaskRunnerHandle> sequenced_task_runner_handle; |
| 236 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle; | 239 std::unique_ptr<ThreadTaskRunnerHandle> single_thread_task_runner_handle; |
| 237 DCHECK(!task->sequenced_task_runner_ref || | 240 DCHECK(!task->sequenced_task_runner_ref || |
| 238 !task->single_thread_task_runner_ref); | 241 !task->single_thread_task_runner_ref); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 254 // TODO(gab): In a better world this would be tacked on as an extra arg | 257 // 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 | 258 // to the trace event generated above. This is not possible however until |
| 256 // http://crbug.com/652692 is resolved. | 259 // http://crbug.com/652692 is resolved. |
| 257 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info", | 260 TRACE_EVENT1("task_scheduler", "TaskTracker::RunTask", "task_info", |
| 258 MakeUnique<TaskTracingInfo>(task->traits, execution_mode, | 261 MakeUnique<TaskTracingInfo>(task->traits, execution_mode, |
| 259 sequence_token)); | 262 sequence_token)); |
| 260 | 263 |
| 261 PerformRunTask(std::move(task)); | 264 PerformRunTask(std::move(task)); |
| 262 } | 265 } |
| 263 | 266 |
| 267 ThreadRestrictions::SetWaitAllowed(previous_wait_allowed); |
| 268 |
| 264 AfterRunTask(shutdown_behavior); | 269 AfterRunTask(shutdown_behavior); |
| 265 } | 270 } |
| 266 | 271 |
| 267 if (!is_delayed) | 272 if (!is_delayed) |
| 268 DecrementNumPendingUndelayedTasks(); | 273 DecrementNumPendingUndelayedTasks(); |
| 269 | 274 |
| 270 return can_run_task; | 275 return can_run_task; |
| 271 } | 276 } |
| 272 | 277 |
| 273 bool TaskTracker::HasShutdownStarted() const { | 278 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); | 447 subtle::NoBarrier_AtomicIncrement(&num_pending_undelayed_tasks_, -1); |
| 443 DCHECK_GE(new_num_pending_undelayed_tasks, 0); | 448 DCHECK_GE(new_num_pending_undelayed_tasks, 0); |
| 444 if (new_num_pending_undelayed_tasks == 0) { | 449 if (new_num_pending_undelayed_tasks == 0) { |
| 445 AutoSchedulerLock auto_lock(flush_lock_); | 450 AutoSchedulerLock auto_lock(flush_lock_); |
| 446 flush_cv_->Signal(); | 451 flush_cv_->Signal(); |
| 447 } | 452 } |
| 448 } | 453 } |
| 449 | 454 |
| 450 } // namespace internal | 455 } // namespace internal |
| 451 } // namespace base | 456 } // namespace base |
| OLD | NEW |