Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: base/task_scheduler/task_scheduler.h

Issue 2764603002: Add TaskScheduler::InitParams and accept it in TaskSchedulerImpl constructor. (Closed)
Patch Set: no offsetof Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/base_export.h" 12 #include "base/base_export.h"
13 #include "base/callback_forward.h" 13 #include "base/callback_forward.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/sequenced_task_runner.h" 15 #include "base/sequenced_task_runner.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/task_runner.h" 17 #include "base/task_runner.h"
18 #include "base/task_scheduler/scheduler_worker_pool_params.h"
18 #include "base/task_scheduler/task_traits.h" 19 #include "base/task_scheduler/task_traits.h"
19 #include "base/time/time.h" 20 #include "base/time/time.h"
20 21
21 namespace gin { 22 namespace gin {
22 class V8Platform; 23 class V8Platform;
23 } 24 }
24 25
25 namespace tracked_objects { 26 namespace tracked_objects {
26 class Location; 27 class Location;
27 } 28 }
28 29
29 namespace base { 30 namespace base {
30 31
31 class HistogramBase; 32 class HistogramBase;
32 class SchedulerWorkerPoolParams;
33 33
34 // Interface for a task scheduler and static methods to manage the instance used 34 // Interface for a task scheduler and static methods to manage the instance used
35 // by the post_task.h API. Note: all base/task_scheduler users should go through 35 // by the post_task.h API. Note: all base/task_scheduler users should go through
36 // post_task.h instead of TaskScheduler except for the one callsite per process 36 // post_task.h instead of TaskScheduler except for the one callsite per process
37 // which manages the process' instance. 37 // which manages the process' instance.
38 class BASE_EXPORT TaskScheduler { 38 class BASE_EXPORT TaskScheduler {
39 public: 39 public:
40 struct BASE_EXPORT InitParams {
41 InitParams(
42 const SchedulerWorkerPoolParams& background_worker_pool_params_in,
43 const SchedulerWorkerPoolParams&
44 background_blocking_worker_pool_params_in,
45 const SchedulerWorkerPoolParams& foreground_worker_pool_params_in,
46 const SchedulerWorkerPoolParams&
47 foreground_blocking_worker_pool_params_in);
48 ~InitParams();
49
50 const SchedulerWorkerPoolParams background_worker_pool_params;
51 const SchedulerWorkerPoolParams background_blocking_worker_pool_params;
52 const SchedulerWorkerPoolParams foreground_worker_pool_params;
53 const SchedulerWorkerPoolParams foreground_blocking_worker_pool_params;
54 };
55
40 // Returns the index of the worker pool in which a task with |traits| should 56 // Returns the index of the worker pool in which a task with |traits| should
41 // run. This should be coded in a future-proof way: new traits should 57 // run. This should be coded in a future-proof way: new traits should
42 // gracefully map to a default pool. 58 // gracefully map to a default pool.
43 using WorkerPoolIndexForTraitsCallback = 59 using WorkerPoolIndexForTraitsCallback =
44 Callback<size_t(const TaskTraits& traits)>; 60 Callback<size_t(const TaskTraits& traits)>;
45 61
46 // Destroying a TaskScheduler is not allowed in production; it is always 62 // Destroying a TaskScheduler is not allowed in production; it is always
47 // leaked. In tests, it should only be destroyed after JoinForTesting() has 63 // leaked. In tests, it should only be destroyed after JoinForTesting() has
48 // returned. 64 // returned.
49 virtual ~TaskScheduler() = default; 65 virtual ~TaskScheduler() = default;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler 130 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler
115 // (ensures isolation). 131 // (ensures isolation).
116 static void CreateAndSetSimpleTaskScheduler(const std::string& name); 132 static void CreateAndSetSimpleTaskScheduler(const std::string& name);
117 #endif // !defined(OS_NACL) 133 #endif // !defined(OS_NACL)
118 134
119 // Creates and sets a task scheduler with custom worker pools. CHECKs on 135 // Creates and sets a task scheduler with custom worker pools. CHECKs on
120 // failure. |worker_pool_params_vector| describes the worker pools to create. 136 // failure. |worker_pool_params_vector| describes the worker pools to create.
121 // |worker_pool_index_for_traits_callback| returns the index in |worker_pools| 137 // |worker_pool_index_for_traits_callback| returns the index in |worker_pools|
122 // of the worker pool in which a task with given traits should run. For tests, 138 // of the worker pool in which a task with given traits should run. For tests,
123 // prefer base::test::ScopedTaskScheduler (ensures isolation). 139 // prefer base::test::ScopedTaskScheduler (ensures isolation).
140 //
141 // Deprecated. Use the overload below instead. https://crbug.com/690706
124 static void CreateAndSetDefaultTaskScheduler( 142 static void CreateAndSetDefaultTaskScheduler(
125 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector, 143 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector,
126 const WorkerPoolIndexForTraitsCallback& 144 const WorkerPoolIndexForTraitsCallback&
127 worker_pool_index_for_traits_callback); 145 worker_pool_index_for_traits_callback);
128 146
147 // Creates and sets a task scheduler using custom params. |name| is used to
148 // label threads and histograms. It should identify the component that creates
149 // the TaskScheduler. |init_params| is used to initialize the worker pools.
150 // CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler
151 // (ensures isolation).
152 //
153 // Note: The names and priority hints in |init_params| are ignored (ref. TODO
154 // to remove them).
155 static void CreateAndSetDefaultTaskScheduler(const std::string& name,
156 const InitParams& init_params);
157
129 // Registers |task_scheduler| to handle tasks posted through the post_task.h 158 // Registers |task_scheduler| to handle tasks posted through the post_task.h
130 // API for this process. For tests, prefer base::test::ScopedTaskScheduler 159 // API for this process. For tests, prefer base::test::ScopedTaskScheduler
131 // (ensures isolation). 160 // (ensures isolation).
132 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); 161 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler);
133 162
134 // Retrieve the TaskScheduler set via SetInstance() or 163 // Retrieve the TaskScheduler set via SetInstance() or
135 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very 164 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very
136 // rarely; most users of TaskScheduler should use the post_task.h API. In 165 // rarely; most users of TaskScheduler should use the post_task.h API. In
137 // particular, refrain from doing 166 // particular, refrain from doing
138 // if (!TaskScheduler::GetInstance()) { 167 // if (!TaskScheduler::GetInstance()) {
(...skipping 16 matching lines...) Expand all
155 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. 184 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items.
156 // 185 //
157 // TODO(fdoray): Remove this method. https://crbug.com/687264 186 // TODO(fdoray): Remove this method. https://crbug.com/687264
158 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( 187 virtual int GetMaxConcurrentTasksWithTraitsDeprecated(
159 const TaskTraits& traits) const = 0; 188 const TaskTraits& traits) const = 0;
160 }; 189 };
161 190
162 } // namespace base 191 } // namespace base
163 192
164 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ 193 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker_pool_params.cc ('k') | base/task_scheduler/task_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698