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

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: tweaks 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.
fdoray 2017/02/24 16:53:37 To be consistent, add: For tests, prefer ...
gab 2017/02/24 17:07:22 Done.
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
fdoray 2017/02/24 16:53:37 CreateAndSet(Simple|Default)TaskScheduler()
gab 2017/02/24 17:07:22 Done.
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. In particular, refrain from doing
132 // if (!TaskScheduler::GetInstance()) {
133 // TaskScheduler::SetInstance(...);
134 // base::PostTask(...);
135 // }
136 // instead make sure to SetInstance() early in one determinstic place in the
137 // process' initialization phase.
138 // In doubt, consult with //base/task_scheduler/OWNERS.
130 static TaskScheduler* GetInstance(); 139 static TaskScheduler* GetInstance();
131 140
132 private: 141 private:
133 friend class gin::V8Platform; 142 friend class gin::V8Platform;
134 143
135 // Returns the maximum number of non-single-threaded tasks posted with 144 // Returns the maximum number of non-single-threaded tasks posted with
136 // |traits| that can run concurrently in this TaskScheduler. 145 // |traits| that can run concurrently in this TaskScheduler.
137 // 146 //
138 // Do not use this method. To process n items, post n tasks that each process 147 // Do not use this method. To process n items, post n tasks that each process
139 // 1 item rather than GetMaxConcurrentTasksWithTraitsDeprecated() tasks that 148 // 1 item rather than GetMaxConcurrentTasksWithTraitsDeprecated() tasks that
140 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. 149 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items.
141 // 150 //
142 // TODO(fdoray): Remove this method. https://crbug.com/687264 151 // TODO(fdoray): Remove this method. https://crbug.com/687264
143 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( 152 virtual int GetMaxConcurrentTasksWithTraitsDeprecated(
144 const TaskTraits& traits) const = 0; 153 const TaskTraits& traits) const = 0;
145 }; 154 };
146 155
147 } // namespace base 156 } // namespace base
148 157
149 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ 158 #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