| 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 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ | 5 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
| 6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ | 6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/synchronization/atomic_flag.h" | 16 #include "base/synchronization/atomic_flag.h" |
| 17 #include "base/task_scheduler/scheduler_worker_pool_impl.h" | 17 #include "base/task_scheduler/scheduler_worker_pool_impl.h" |
| 18 #include "base/task_scheduler/sequence.h" | 18 #include "base/task_scheduler/sequence.h" |
| 19 #include "base/task_scheduler/task_scheduler.h" | 19 #include "base/task_scheduler/task_scheduler.h" |
| 20 #include "base/task_scheduler/task_tracker.h" |
| 20 #include "base/task_scheduler/task_traits.h" | 21 #include "base/task_scheduler/task_traits.h" |
| 21 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 22 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 23 | 24 |
| 25 #if defined(OS_POSIX) && !defined(OS_NACL_SFI) |
| 26 #include "base/task_scheduler/task_tracker_posix.h" |
| 27 #endif |
| 28 |
| 24 namespace base { | 29 namespace base { |
| 25 | 30 |
| 26 class HistogramBase; | 31 class HistogramBase; |
| 27 | 32 |
| 28 namespace internal { | 33 namespace internal { |
| 29 | 34 |
| 30 class DelayedTaskManager; | 35 class DelayedTaskManager; |
| 31 class SchedulerSingleThreadTaskRunnerManager; | 36 class SchedulerSingleThreadTaskRunnerManager; |
| 32 class TaskTracker; | |
| 33 | 37 |
| 34 // Default TaskScheduler implementation. This class is thread-safe. | 38 // Default TaskScheduler implementation. This class is thread-safe. |
| 35 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler { | 39 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler { |
| 36 public: | 40 public: |
| 37 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure. | 41 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure. |
| 38 // |name| is used to label threads and histograms. It should identify the | 42 // |name| is used to label threads and histograms. It should identify the |
| 39 // component that creates the TaskScheduler. |init_params| contains params to | 43 // component that creates the TaskScheduler. |init_params| contains params to |
| 40 // initialize worker pools. | 44 // initialize worker pools. |
| 41 // | 45 // |
| 42 // Note: The names and priority hints in |init_params| are ignored. | 46 // Note: The names and priority hints in |init_params| are ignored. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 // Returns the worker pool that runs Tasks with |traits|. | 81 // Returns the worker pool that runs Tasks with |traits|. |
| 78 SchedulerWorkerPoolImpl* GetWorkerPoolForTraits( | 82 SchedulerWorkerPoolImpl* GetWorkerPoolForTraits( |
| 79 const TaskTraits& traits) const; | 83 const TaskTraits& traits) const; |
| 80 | 84 |
| 81 // Callback invoked when a non-single-thread |sequence| isn't empty after a | 85 // Callback invoked when a non-single-thread |sequence| isn't empty after a |
| 82 // worker pops a Task from it. | 86 // worker pops a Task from it. |
| 83 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence); | 87 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence); |
| 84 | 88 |
| 85 const std::string name_; | 89 const std::string name_; |
| 86 Thread service_thread_; | 90 Thread service_thread_; |
| 87 std::unique_ptr<TaskTracker> task_tracker_; | 91 #if defined(OS_POSIX) && !defined(OS_NACL_SFI) |
| 92 TaskTrackerPosix task_tracker_; |
| 93 #else |
| 94 TaskTracker task_tracker_; |
| 95 #endif |
| 88 std::unique_ptr<DelayedTaskManager> delayed_task_manager_; | 96 std::unique_ptr<DelayedTaskManager> delayed_task_manager_; |
| 89 std::unique_ptr<SchedulerSingleThreadTaskRunnerManager> | 97 std::unique_ptr<SchedulerSingleThreadTaskRunnerManager> |
| 90 single_thread_task_runner_manager_; | 98 single_thread_task_runner_manager_; |
| 91 | 99 |
| 92 // There are 4 SchedulerWorkerPoolImpl in this array to match the 4 | 100 // There are 4 SchedulerWorkerPoolImpl in this array to match the 4 |
| 93 // SchedulerWorkerPoolParams in TaskScheduler::InitParams. | 101 // SchedulerWorkerPoolParams in TaskScheduler::InitParams. |
| 94 std::unique_ptr<SchedulerWorkerPoolImpl> worker_pools_[4]; | 102 std::unique_ptr<SchedulerWorkerPoolImpl> worker_pools_[4]; |
| 95 | 103 |
| 96 #if DCHECK_IS_ON() | 104 #if DCHECK_IS_ON() |
| 97 // Set once JoinForTesting() has returned. | 105 // Set once JoinForTesting() has returned. |
| 98 AtomicFlag join_for_testing_returned_; | 106 AtomicFlag join_for_testing_returned_; |
| 99 #endif | 107 #endif |
| 100 | 108 |
| 101 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); | 109 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); |
| 102 }; | 110 }; |
| 103 | 111 |
| 104 } // namespace internal | 112 } // namespace internal |
| 105 } // namespace base | 113 } // namespace base |
| 106 | 114 |
| 107 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ | 115 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
| OLD | NEW |