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

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: 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
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.
118 static void CreateAndSetDefaultTaskScheduler( 119 static void CreateAndSetDefaultTaskScheduler(
119 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector, 120 const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector,
120 const WorkerPoolIndexForTraitsCallback& 121 const WorkerPoolIndexForTraitsCallback&
121 worker_pool_index_for_traits_callback); 122 worker_pool_index_for_traits_callback);
122 123
123 // Registers |task_scheduler| to handle tasks posted through the post_task.h 124 // Registers |task_scheduler| to handle tasks posted through the post_task.h
124 // API for this process. 125 // API for this process. For tests, prefer base::test::ScopedTaskScheduler
126 // (ensures isolation).
125 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); 127 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler);
126 128
127 // Retrieve the TaskScheduler set via CreateAndSetDefaultTaskScheduler() or 129 // Retrieve the TaskScheduler set via CreateAndSetDefaultTaskScheduler() or
128 // SetInstance(). This should be used very rarely; most users of TaskScheduler 130 // SetInstance(). This should be used very rarely; most users of TaskScheduler
129 // should use the post_task.h API. 131 // should use the post_task.h API.
130 static TaskScheduler* GetInstance(); 132 static TaskScheduler* GetInstance();
robliao 2017/02/23 23:00:33 Might as well hammer home not to call this just to
gab 2017/02/23 23:39:57 Hehe, I just did that as part of resolving your pr
131 133
132 private: 134 private:
133 friend class gin::V8Platform; 135 friend class gin::V8Platform;
134 136
135 // Returns the maximum number of non-single-threaded tasks posted with 137 // Returns the maximum number of non-single-threaded tasks posted with
136 // |traits| that can run concurrently in this TaskScheduler. 138 // |traits| that can run concurrently in this TaskScheduler.
137 // 139 //
138 // Do not use this method. To process n items, post n tasks that each process 140 // Do not use this method. To process n items, post n tasks that each process
139 // 1 item rather than GetMaxConcurrentTasksWithTraitsDeprecated() tasks that 141 // 1 item rather than GetMaxConcurrentTasksWithTraitsDeprecated() tasks that
140 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. 142 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items.
141 // 143 //
142 // TODO(fdoray): Remove this method. https://crbug.com/687264 144 // TODO(fdoray): Remove this method. https://crbug.com/687264
143 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( 145 virtual int GetMaxConcurrentTasksWithTraitsDeprecated(
144 const TaskTraits& traits) const = 0; 146 const TaskTraits& traits) const = 0;
145 }; 147 };
146 148
147 } // namespace base 149 } // namespace base
148 150
149 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ 151 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_
OLDNEW
« base/task_scheduler/post_task.cc ('K') | « base/task_scheduler/post_task.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698