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

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

Issue 2836033002: Add TaskScheduler::Create and TaskScheduler::CreateAndStartWithDefaultParams. (Closed)
Patch Set: self-review 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
« no previous file with comments | « no previous file | base/task_scheduler/task_scheduler.cc » ('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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // Does not wait for delayed tasks. Waits for undelayed tasks posted from 127 // Does not wait for delayed tasks. Waits for undelayed tasks posted from
128 // other threads during the call. Returns immediately when shutdown completes. 128 // other threads during the call. Returns immediately when shutdown completes.
129 virtual void FlushForTesting() = 0; 129 virtual void FlushForTesting() = 0;
130 130
131 // Joins all threads. Tasks that are already running are allowed to complete 131 // Joins all threads. Tasks that are already running are allowed to complete
132 // their execution. This can only be called once. Using this task scheduler 132 // their execution. This can only be called once. Using this task scheduler
133 // instance to create task runners or post tasks is not permitted during or 133 // instance to create task runners or post tasks is not permitted during or
134 // after this call. 134 // after this call.
135 virtual void JoinForTesting() = 0; 135 virtual void JoinForTesting() = 0;
136 136
137 // CreateAndSetSimpleTaskScheduler(), CreateAndSetDefaultTaskScheduler(), and 137 // CreateAndStartWithDefaultParams(), Create(), and SetInstance() register a
138 // SetInstance() register a TaskScheduler to handle tasks posted through the 138 // TaskScheduler to handle tasks posted through the post_task.h API for this
139 // post_task.h API for this process. The registered TaskScheduler will only be 139 // process.
140 // deleted when a new TaskScheduler is registered and is leaked on shutdown. 140 //
141 // The methods must not be called when TaskRunners created by the previous 141 // Processes that need to initialize TaskScheduler with custom params or that
142 // TaskScheduler are still alive. The methods are not thread-safe; proper 142 // need to allow tasks to be posted before the TaskScheduler creates its
143 // synchronization is required to use the post_task.h API after registering a 143 // threads should use Create() followed by Start(). Other processes can use
144 // new TaskScheduler. 144 // CreateAndStartWithDefaultParams().
145 //
146 // A registered TaskScheduler is only deleted when a new TaskScheduler is
147 // registered. The last registered TaskScheduler is leaked on shutdown. The
148 // methods below must not be called when TaskRunners created by a previous
149 // TaskScheduler are still alive. The methods are not thread-safe; proper
150 // synchronization is required to use the post_task.h API after registering a
151 // new TaskScheduler.
145 152
146 #if !defined(OS_NACL) 153 #if !defined(OS_NACL)
147 // Creates and sets a task scheduler using default params. |name| is used to 154 // Creates and starts a task scheduler using default params. |name| is used to
148 // label threads and histograms. It should identify the component that calls 155 // label threads and histograms. It should identify the component that calls
149 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler 156 // this. Start() is called by this method; it is invalid to call it again
150 // (ensures isolation). 157 // afterwards. CHECKs on failure. For tests, prefer
158 // base::test::ScopedTaskEnvironment (ensures isolation).
159 static void CreateAndStartWithDefaultParams(StringPiece name);
160
161 // Deprecated. Use CreateAndStartWithDefaultParams() instead.
162 // TODO(fdoray): Redirect callers to CreateAndStartWithDefaultParams().
151 static void CreateAndSetSimpleTaskScheduler(StringPiece name); 163 static void CreateAndSetSimpleTaskScheduler(StringPiece name);
152 #endif // !defined(OS_NACL) 164 #endif // !defined(OS_NACL)
153 165
154 // Creates and sets a task scheduler using custom params. |name| is used to 166 // Creates a ready to start task scheduler. |name| is used to label threads
155 // label threads and histograms. It should identify the component that creates 167 // and histograms. It should identify the component that creates the
156 // the TaskScheduler. |init_params| is used to initialize the worker pools. 168 // TaskScheduler. The task scheduler doesn't create threads until Start() is
157 // CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler 169 // called. Tasks can be posted at any time but will not run until after
170 // Start() is called. For tests, prefer base::test::ScopedTaskEnvironment
158 // (ensures isolation). 171 // (ensures isolation).
172 static void Create(StringPiece name);
173
174 // Deprecated. Use Create() and Start() instead.
175 // TODO(fdoray): Redirect callers to Create() and Start().
159 static void CreateAndSetDefaultTaskScheduler(StringPiece name, 176 static void CreateAndSetDefaultTaskScheduler(StringPiece name,
160 const InitParams& init_params); 177 const InitParams& init_params);
161 178
162 // Registers |task_scheduler| to handle tasks posted through the post_task.h 179 // Registers |task_scheduler| to handle tasks posted through the post_task.h
163 // API for this process. For tests, prefer base::test::ScopedTaskScheduler 180 // API for this process. For tests, prefer base::test::ScopedTaskScheduler
164 // (ensures isolation). 181 // (ensures isolation).
165 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); 182 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler);
166 183
167 // Retrieve the TaskScheduler set via SetInstance() or 184 // Retrieve the TaskScheduler set via SetInstance() or
168 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very 185 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very
(...skipping 19 matching lines...) Expand all
188 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. 205 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items.
189 // 206 //
190 // TODO(fdoray): Remove this method. https://crbug.com/687264 207 // TODO(fdoray): Remove this method. https://crbug.com/687264
191 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( 208 virtual int GetMaxConcurrentTasksWithTraitsDeprecated(
192 const TaskTraits& traits) const = 0; 209 const TaskTraits& traits) const = 0;
193 }; 210 };
194 211
195 } // namespace base 212 } // namespace base
196 213
197 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ 214 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_
OLDNEW
« no previous file with comments | « no previous file | base/task_scheduler/task_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698