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

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

Issue 2834063002: Separate the create and start phases in TaskSchedulerImpl. (Closed)
Patch Set: CR-robliao-25-grammar Created 3 years, 7 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/scheduler_worker_pool_impl.h ('k') | 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 15 matching lines...) Expand all
26 26
27 namespace tracked_objects { 27 namespace tracked_objects {
28 class Location; 28 class Location;
29 } 29 }
30 30
31 namespace base { 31 namespace base {
32 32
33 class HistogramBase; 33 class HistogramBase;
34 34
35 // Interface for a task scheduler and static methods to manage the instance used 35 // Interface for a task scheduler and static methods to manage the instance used
36 // by the post_task.h API. Note: all base/task_scheduler users should go through 36 // by the post_task.h API.
37 // post_task.h instead of TaskScheduler except for the one callsite per process 37 //
38 // which manages the process' instance. 38 // The task scheduler doesn't create threads until Start() is called. Tasks can
39 // be posted at any time but will not run until after Start() is called.
40 //
41 // The instance methods of this class are thread-safe.
42 //
43 // Note: All base/task_scheduler users should go through post_task.h instead of
44 // TaskScheduler except for the one callsite per process which manages the
45 // process's instance.
39 class BASE_EXPORT TaskScheduler { 46 class BASE_EXPORT TaskScheduler {
40 public: 47 public:
41 struct BASE_EXPORT InitParams { 48 struct BASE_EXPORT InitParams {
42 InitParams( 49 InitParams(
43 const SchedulerWorkerPoolParams& background_worker_pool_params_in, 50 const SchedulerWorkerPoolParams& background_worker_pool_params_in,
44 const SchedulerWorkerPoolParams& 51 const SchedulerWorkerPoolParams&
45 background_blocking_worker_pool_params_in, 52 background_blocking_worker_pool_params_in,
46 const SchedulerWorkerPoolParams& foreground_worker_pool_params_in, 53 const SchedulerWorkerPoolParams& foreground_worker_pool_params_in,
47 const SchedulerWorkerPoolParams& 54 const SchedulerWorkerPoolParams&
48 foreground_blocking_worker_pool_params_in); 55 foreground_blocking_worker_pool_params_in);
49 ~InitParams(); 56 ~InitParams();
50 57
51 const SchedulerWorkerPoolParams background_worker_pool_params; 58 const SchedulerWorkerPoolParams background_worker_pool_params;
52 const SchedulerWorkerPoolParams background_blocking_worker_pool_params; 59 const SchedulerWorkerPoolParams background_blocking_worker_pool_params;
53 const SchedulerWorkerPoolParams foreground_worker_pool_params; 60 const SchedulerWorkerPoolParams foreground_worker_pool_params;
54 const SchedulerWorkerPoolParams foreground_blocking_worker_pool_params; 61 const SchedulerWorkerPoolParams foreground_blocking_worker_pool_params;
55 }; 62 };
56 63
57 // Destroying a TaskScheduler is not allowed in production; it is always 64 // Destroying a TaskScheduler is not allowed in production; it is always
58 // leaked. In tests, it should only be destroyed after JoinForTesting() has 65 // leaked. In tests, it should only be destroyed after JoinForTesting() has
59 // returned. 66 // returned.
60 virtual ~TaskScheduler() = default; 67 virtual ~TaskScheduler() = default;
61 68
69 // Allows the task scheduler to create threads and run tasks following the
70 // |init_params| specification. CHECKs on failure.
71 virtual void Start(const InitParams& init_params) = 0;
72
62 // Posts |task| with a |delay| and specific |traits|. |delay| can be zero. 73 // Posts |task| with a |delay| and specific |traits|. |delay| can be zero.
63 // For one off tasks that don't require a TaskRunner. 74 // For one off tasks that don't require a TaskRunner.
64 virtual void PostDelayedTaskWithTraits( 75 virtual void PostDelayedTaskWithTraits(
65 const tracked_objects::Location& from_here, 76 const tracked_objects::Location& from_here,
66 const TaskTraits& traits, 77 const TaskTraits& traits,
67 OnceClosure task, 78 OnceClosure task,
68 TimeDelta delay) = 0; 79 TimeDelta delay) = 0;
69 80
70 // Returns a TaskRunner whose PostTask invocations result in scheduling tasks 81 // Returns a TaskRunner whose PostTask invocations result in scheduling tasks
71 // using |traits|. Tasks may run in any order and in parallel. 82 // using |traits|. Tasks may run in any order and in parallel.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. 188 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items.
178 // 189 //
179 // TODO(fdoray): Remove this method. https://crbug.com/687264 190 // TODO(fdoray): Remove this method. https://crbug.com/687264
180 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( 191 virtual int GetMaxConcurrentTasksWithTraitsDeprecated(
181 const TaskTraits& traits) const = 0; 192 const TaskTraits& traits) const = 0;
182 }; 193 };
183 194
184 } // namespace base 195 } // namespace base
185 196
186 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ 197 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_
OLDNEW
« no previous file with comments | « base/task_scheduler/scheduler_worker_pool_impl.h ('k') | base/task_scheduler/task_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698