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

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

Issue 2709163006: Update TaskScheduler docs to make it more obvious how a TaskScheduler should be put in place. (Closed)
Patch Set: review:fdoray Created 3 years, 10 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
« no previous file with comments | « base/task_scheduler/post_task.cc ('k') | base/task_scheduler/task_traits.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <vector> 9 #include <vector>
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // CreateAndSetSimpleTaskScheduler(), CreateAndSetDefaultTaskScheduler(), and 101 // CreateAndSetSimpleTaskScheduler(), CreateAndSetDefaultTaskScheduler(), and
102 // SetInstance() register a TaskScheduler to handle tasks posted through the 102 // SetInstance() register a TaskScheduler to handle tasks posted through the
103 // post_task.h API for this process. The registered TaskScheduler will only be 103 // 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. 104 // 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 105 // The methods must not be called when TaskRunners created by the previous
106 // TaskScheduler are still alive. The methods are not thread-safe; proper 106 // 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 107 // synchronization is required to use the post_task.h API after registering a
108 // new TaskScheduler. 108 // new TaskScheduler.
109 109
110 // Creates and sets a task scheduler with one worker pool that can have up to 110 // Creates and sets a task scheduler with one worker pool that can have up to
111 // |max_threads| threads. CHECKs on failure. 111 // |max_threads| threads. CHECKs on failure. For tests, prefer
112 // base::test::ScopedTaskScheduler (ensures isolation).
112 static void CreateAndSetSimpleTaskScheduler(int max_threads); 113 static void CreateAndSetSimpleTaskScheduler(int max_threads);
113 114
114 // Creates and sets a task scheduler with custom worker pools. CHECKs on 115 // Creates and sets a task scheduler with custom worker pools. CHECKs on
115 // failure. |worker_pool_params_vector| describes the worker pools to create. 116 // failure. |worker_pool_params_vector| describes the worker pools to create.
116 // |worker_pool_index_for_traits_callback| returns the index in |worker_pools| 117 // |worker_pool_index_for_traits_callback| returns the index in |worker_pools|
117 // of the worker pool in which a task with given traits should run. 118 // of the worker pool in which a task with given traits should run. For tests,
119 // prefer base::test::ScopedTaskScheduler (ensures isolation).
118 static void CreateAndSetDefaultTaskScheduler( 120 static void CreateAndSetDefaultTaskScheduler(
119 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector, 121 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector,
120 const WorkerPoolIndexForTraitsCallback& 122 const WorkerPoolIndexForTraitsCallback&
121 worker_pool_index_for_traits_callback); 123 worker_pool_index_for_traits_callback);
122 124
123 // Registers |task_scheduler| to handle tasks posted through the post_task.h 125 // Registers |task_scheduler| to handle tasks posted through the post_task.h
124 // API for this process. 126 // API for this process. For tests, prefer base::test::ScopedTaskScheduler
127 // (ensures isolation).
125 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); 128 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler);
126 129
127 // Retrieve the TaskScheduler set via CreateAndSetDefaultTaskScheduler() or 130 // Retrieve the TaskScheduler set via SetInstance() or
128 // SetInstance(). This should be used very rarely; most users of TaskScheduler 131 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very
129 // should use the post_task.h API. 132 // rarely; most users of TaskScheduler should use the post_task.h API. In
133 // particular, refrain from doing
134 // if (!TaskScheduler::GetInstance()) {
135 // TaskScheduler::SetInstance(...);
136 // base::PostTask(...);
137 // }
138 // instead make sure to SetInstance() early in one determinstic place in the
139 // process' initialization phase.
140 // In doubt, consult with //base/task_scheduler/OWNERS.
130 static TaskScheduler* GetInstance(); 141 static TaskScheduler* GetInstance();
131 142
132 private: 143 private:
133 friend class gin::V8Platform; 144 friend class gin::V8Platform;
134 145
135 // Returns the maximum number of non-single-threaded tasks posted with 146 // Returns the maximum number of non-single-threaded tasks posted with
136 // |traits| that can run concurrently in this TaskScheduler. 147 // |traits| that can run concurrently in this TaskScheduler.
137 // 148 //
138 // Do not use this method. To process n items, post n tasks that each process 149 // Do not use this method. To process n items, post n tasks that each process
139 // 1 item rather than GetMaxConcurrentTasksWithTraitsDeprecated() tasks that 150 // 1 item rather than GetMaxConcurrentTasksWithTraitsDeprecated() tasks that
140 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. 151 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items.
141 // 152 //
142 // TODO(fdoray): Remove this method. https://crbug.com/687264 153 // TODO(fdoray): Remove this method. https://crbug.com/687264
143 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( 154 virtual int GetMaxConcurrentTasksWithTraitsDeprecated(
144 const TaskTraits& traits) const = 0; 155 const TaskTraits& traits) const = 0;
145 }; 156 };
146 157
147 } // namespace base 158 } // namespace base
148 159
149 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ 160 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_
OLDNEW
« no previous file with comments | « base/task_scheduler/post_task.cc ('k') | base/task_scheduler/task_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698