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_H_ | 5 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ | 6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
| 9 #include <string> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/base_export.h" | 12 #include "base/base_export.h" |
12 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
15 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
16 #include "base/task_runner.h" | 17 #include "base/task_runner.h" |
17 #include "base/task_scheduler/task_traits.h" | 18 #include "base/task_scheduler/task_traits.h" |
18 #include "base/time/time.h" | 19 #include "base/time/time.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 101 |
101 // CreateAndSetSimpleTaskScheduler(), CreateAndSetDefaultTaskScheduler(), and | 102 // CreateAndSetSimpleTaskScheduler(), CreateAndSetDefaultTaskScheduler(), and |
102 // SetInstance() register a TaskScheduler to handle tasks posted through the | 103 // SetInstance() register a TaskScheduler to handle tasks posted through the |
103 // post_task.h API for this process. The registered TaskScheduler will only be | 104 // post_task.h API for this process. The registered TaskScheduler will only be |
104 // deleted when a new TaskScheduler is registered and is leaked on shutdown. | 105 // deleted when a new TaskScheduler is registered and is leaked on shutdown. |
105 // The methods must not be called when TaskRunners created by the previous | 106 // The methods must not be called when TaskRunners created by the previous |
106 // TaskScheduler are still alive. The methods are not thread-safe; proper | 107 // TaskScheduler are still alive. The methods are not thread-safe; proper |
107 // synchronization is required to use the post_task.h API after registering a | 108 // synchronization is required to use the post_task.h API after registering a |
108 // new TaskScheduler. | 109 // new TaskScheduler. |
109 | 110 |
110 // Creates and sets a task scheduler with one worker pool that can have up to | 111 // Creates and sets a task scheduler using default params. |name| is used to |
111 // |max_threads| threads. CHECKs on failure. For tests, prefer | 112 // label threads and histograms. It should identify the component that calls |
112 // base::test::ScopedTaskScheduler (ensures isolation). | 113 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler |
113 static void CreateAndSetSimpleTaskScheduler(int max_threads); | 114 // (ensures isolation). |
| 115 static void CreateAndSetSimpleTaskScheduler(const std::string& name); |
114 | 116 |
115 // Creates and sets a task scheduler with custom worker pools. CHECKs on | 117 // Creates and sets a task scheduler with custom worker pools. CHECKs on |
116 // failure. |worker_pool_params_vector| describes the worker pools to create. | 118 // failure. |worker_pool_params_vector| describes the worker pools to create. |
117 // |worker_pool_index_for_traits_callback| returns the index in |worker_pools| | 119 // |worker_pool_index_for_traits_callback| returns the index in |worker_pools| |
118 // of the worker pool in which a task with given traits should run. For tests, | 120 // of the worker pool in which a task with given traits should run. For tests, |
119 // prefer base::test::ScopedTaskScheduler (ensures isolation). | 121 // prefer base::test::ScopedTaskScheduler (ensures isolation). |
120 static void CreateAndSetDefaultTaskScheduler( | 122 static void CreateAndSetDefaultTaskScheduler( |
121 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector, | 123 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector, |
122 const WorkerPoolIndexForTraitsCallback& | 124 const WorkerPoolIndexForTraitsCallback& |
123 worker_pool_index_for_traits_callback); | 125 worker_pool_index_for_traits_callback); |
(...skipping 27 matching lines...) Expand all Loading... |
151 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. | 153 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. |
152 // | 154 // |
153 // TODO(fdoray): Remove this method. https://crbug.com/687264 | 155 // TODO(fdoray): Remove this method. https://crbug.com/687264 |
154 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( | 156 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( |
155 const TaskTraits& traits) const = 0; | 157 const TaskTraits& traits) const = 0; |
156 }; | 158 }; |
157 | 159 |
158 } // namespace base | 160 } // namespace base |
159 | 161 |
160 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ | 162 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ |
OLD | NEW |