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

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

Issue 2836033002: Add TaskScheduler::Create and TaskScheduler::CreateAndStartWithDefaultParams. (Closed)
Patch Set: 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 // Does not wait for delayed tasks. Waits for undelayed tasks posted from 128 // Does not wait for delayed tasks. Waits for undelayed tasks posted from
129 // other threads during the call. Returns immediately when shutdown completes. 129 // other threads during the call. Returns immediately when shutdown completes.
130 virtual void FlushForTesting() = 0; 130 virtual void FlushForTesting() = 0;
131 131
132 // Joins all threads. Tasks that are already running are allowed to complete 132 // Joins all threads. Tasks that are already running are allowed to complete
133 // their execution. This can only be called once. Using this task scheduler 133 // their execution. This can only be called once. Using this task scheduler
134 // instance to create task runners or post tasks is not permitted during or 134 // instance to create task runners or post tasks is not permitted during or
135 // after this call. 135 // after this call.
136 virtual void JoinForTesting() = 0; 136 virtual void JoinForTesting() = 0;
137 137
138 // CreateAndSetSimpleTaskScheduler(), CreateAndSetDefaultTaskScheduler(), and 138 // CreateAndStartWithDefaultParams(), Create(), and SetInstance() register a
robliao 2017/04/24 22:37:27 Discuss when one would use Create vs CreateAndStar
fdoray 2017/04/25 21:56:11 Done.
139 // SetInstance() register a TaskScheduler to handle tasks posted through the 139 // TaskScheduler to handle tasks posted through the post_task.h API for this
140 // post_task.h API for this process. The registered TaskScheduler will only be 140 // process. The registered TaskScheduler will only be deleted when a new
141 // deleted when a new TaskScheduler is registered and is leaked on shutdown. 141 // TaskScheduler is registered and is leaked on shutdown. The methods must not
142 // The methods must not be called when TaskRunners created by the previous 142 // be called when TaskRunners created by the previous TaskScheduler are still
143 // TaskScheduler are still alive. The methods are not thread-safe; proper 143 // alive. The methods are not thread-safe; proper synchronization is required to
144 // synchronization is required to use the post_task.h API after registering a 144 // use the post_task.h API after registering a new TaskScheduler.
145 // new TaskScheduler.
146 145
147 #if !defined(OS_NACL) 146 #if !defined(OS_NACL)
148 // Creates and sets a task scheduler using default params. |name| is used to 147 // Creates and starts a task scheduler using default params. |name| is used to
149 // label threads and histograms. It should identify the component that calls 148 // label threads and histograms. It should identify the component that calls
150 // this. CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler 149 // this. Start() is called by this method; it is invalid to call it again
151 // (ensures isolation). 150 // afterwards. CHECKs on failure. For tests, prefer
151 // base::test::ScopedTaskEnvironment (ensures isolation).
152 static void CreateAndStartWithDefaultParams(StringPiece name);
153
154 // Deprecated.
152 static void CreateAndSetSimpleTaskScheduler(StringPiece name); 155 static void CreateAndSetSimpleTaskScheduler(StringPiece name);
153 #endif // !defined(OS_NACL) 156 #endif // !defined(OS_NACL)
154 157
155 // Creates and sets a task scheduler using custom params. |name| is used to 158 // Creates a task scheduler. |name| is used to label threads and histograms.
robliao 2017/04/24 22:37:27 Creates a ready to start task scheduler.
fdoray 2017/04/25 21:56:10 Done.
156 // label threads and histograms. It should identify the component that creates 159 // It should identify the component that creates the TaskScheduler. The task
157 // the TaskScheduler. |init_params| is used to initialize the worker pools. 160 // scheduler doesn't create threads until Start() is called on
158 // CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler 161 // TaskScheduler::GetInstance(). Tasks can be posted before Start() is called,
159 // (ensures isolation). 162 // but they don't run until Start() is called. For tests, prefer
163 // base::test::ScopedTaskEnvironment (ensures isolation).
164 static void Create(StringPiece name);
165
166 // Deprecated.
160 static void CreateAndSetDefaultTaskScheduler(StringPiece name, 167 static void CreateAndSetDefaultTaskScheduler(StringPiece name,
161 const InitParams& init_params); 168 const InitParams& init_params);
162 169
163 // Registers |task_scheduler| to handle tasks posted through the post_task.h 170 // Registers |task_scheduler| to handle tasks posted through the post_task.h
164 // API for this process. For tests, prefer base::test::ScopedTaskScheduler 171 // API for this process. For tests, prefer base::test::ScopedTaskScheduler
165 // (ensures isolation). 172 // (ensures isolation).
166 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler); 173 static void SetInstance(std::unique_ptr<TaskScheduler> task_scheduler);
167 174
168 // Retrieve the TaskScheduler set via SetInstance() or 175 // Retrieve the TaskScheduler set via SetInstance() or
169 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very 176 // CreateAndSet(Simple|Default)TaskScheduler(). This should be used very
(...skipping 19 matching lines...) Expand all
189 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. 196 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items.
190 // 197 //
191 // TODO(fdoray): Remove this method. https://crbug.com/687264 198 // TODO(fdoray): Remove this method. https://crbug.com/687264
192 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( 199 virtual int GetMaxConcurrentTasksWithTraitsDeprecated(
193 const TaskTraits& traits) const = 0; 200 const TaskTraits& traits) const = 0;
194 }; 201 };
195 202
196 } // namespace base 203 } // namespace base
197 204
198 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ 205 #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