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