| 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/strings/string_piece.h" |
| 16 #include "base/synchronization/atomic_flag.h" | 17 #include "base/synchronization/atomic_flag.h" |
| 17 #include "base/task_scheduler/scheduler_worker_pool_impl.h" | 18 #include "base/task_scheduler/scheduler_worker_pool_impl.h" |
| 18 #include "base/task_scheduler/sequence.h" | 19 #include "base/task_scheduler/sequence.h" |
| 19 #include "base/task_scheduler/task_scheduler.h" | 20 #include "base/task_scheduler/task_scheduler.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 |
| 24 namespace base { | 25 namespace base { |
| 25 | 26 |
| 26 class HistogramBase; | 27 class HistogramBase; |
| 27 | 28 |
| 28 namespace internal { | 29 namespace internal { |
| 29 | 30 |
| 30 class DelayedTaskManager; | 31 class DelayedTaskManager; |
| 31 class SchedulerSingleThreadTaskRunnerManager; | 32 class SchedulerSingleThreadTaskRunnerManager; |
| 32 class TaskTracker; | 33 class TaskTracker; |
| 33 | 34 |
| 34 // Default TaskScheduler implementation. This class is thread-safe. | 35 // Default TaskScheduler implementation. This class is thread-safe. |
| 35 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler { | 36 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler { |
| 36 public: | 37 public: |
| 37 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure. | 38 // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure. |
| 38 // |name| is used to label threads and histograms. It should identify the | 39 // |name| is used to label threads and histograms. It should identify the |
| 39 // component that creates the TaskScheduler. |init_params| contains params to | 40 // component that creates the TaskScheduler. |init_params| contains params to |
| 40 // initialize worker pools. | 41 // initialize worker pools. |
| 41 // | 42 // |
| 42 // Note: The names and priority hints in |init_params| are ignored. | 43 // Note: The names and priority hints in |init_params| are ignored. |
| 43 // https://crbug.com/690706 | 44 // https://crbug.com/690706 |
| 44 static std::unique_ptr<TaskSchedulerImpl> Create( | 45 static std::unique_ptr<TaskSchedulerImpl> Create( |
| 45 const std::string& name, | 46 StringPiece name, |
| 46 const TaskScheduler::InitParams& init_params); | 47 const TaskScheduler::InitParams& init_params); |
| 47 | 48 |
| 48 ~TaskSchedulerImpl() override; | 49 ~TaskSchedulerImpl() override; |
| 49 | 50 |
| 50 // TaskScheduler: | 51 // TaskScheduler: |
| 51 void PostDelayedTaskWithTraits(const tracked_objects::Location& from_here, | 52 void PostDelayedTaskWithTraits(const tracked_objects::Location& from_here, |
| 52 const TaskTraits& traits, | 53 const TaskTraits& traits, |
| 53 OnceClosure task, | 54 OnceClosure task, |
| 54 TimeDelta delay) override; | 55 TimeDelta delay) override; |
| 55 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | 56 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
| 56 const TaskTraits& traits) override; | 57 const TaskTraits& traits) override; |
| 57 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits( | 58 scoped_refptr<SequencedTaskRunner> CreateSequencedTaskRunnerWithTraits( |
| 58 const TaskTraits& traits) override; | 59 const TaskTraits& traits) override; |
| 59 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( | 60 scoped_refptr<SingleThreadTaskRunner> CreateSingleThreadTaskRunnerWithTraits( |
| 60 const TaskTraits& traits) override; | 61 const TaskTraits& traits) override; |
| 61 #if defined(OS_WIN) | 62 #if defined(OS_WIN) |
| 62 scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunnerWithTraits( | 63 scoped_refptr<SingleThreadTaskRunner> CreateCOMSTATaskRunnerWithTraits( |
| 63 const TaskTraits& traits) override; | 64 const TaskTraits& traits) override; |
| 64 #endif // defined(OS_WIN) | 65 #endif // defined(OS_WIN) |
| 65 std::vector<const HistogramBase*> GetHistograms() const override; | 66 std::vector<const HistogramBase*> GetHistograms() const override; |
| 66 int GetMaxConcurrentTasksWithTraitsDeprecated( | 67 int GetMaxConcurrentTasksWithTraitsDeprecated( |
| 67 const TaskTraits& traits) const override; | 68 const TaskTraits& traits) const override; |
| 68 void Shutdown() override; | 69 void Shutdown() override; |
| 69 void FlushForTesting() override; | 70 void FlushForTesting() override; |
| 70 void JoinForTesting() override; | 71 void JoinForTesting() override; |
| 71 | 72 |
| 72 private: | 73 private: |
| 73 explicit TaskSchedulerImpl(const std::string& name); | 74 explicit TaskSchedulerImpl(StringPiece name); |
| 74 | 75 |
| 75 void Initialize(const TaskScheduler::InitParams& init_params); | 76 void Initialize(const TaskScheduler::InitParams& init_params); |
| 76 | 77 |
| 77 // Returns the worker pool that runs Tasks with |traits|. | 78 // Returns the worker pool that runs Tasks with |traits|. |
| 78 SchedulerWorkerPoolImpl* GetWorkerPoolForTraits( | 79 SchedulerWorkerPoolImpl* GetWorkerPoolForTraits( |
| 79 const TaskTraits& traits) const; | 80 const TaskTraits& traits) const; |
| 80 | 81 |
| 81 // Callback invoked when a non-single-thread |sequence| isn't empty after a | 82 // Callback invoked when a non-single-thread |sequence| isn't empty after a |
| 82 // worker pops a Task from it. | 83 // worker pops a Task from it. |
| 83 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence); | 84 void ReEnqueueSequenceCallback(scoped_refptr<Sequence> sequence); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 95 AtomicFlag join_for_testing_returned_; | 96 AtomicFlag join_for_testing_returned_; |
| 96 #endif | 97 #endif |
| 97 | 98 |
| 98 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); | 99 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 } // namespace internal | 102 } // namespace internal |
| 102 } // namespace base | 103 } // namespace base |
| 103 | 104 |
| 104 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ | 105 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
| OLD | NEW |