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

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

Issue 2873733003: Introduce SingleThreadTaskRunnerThreadMode (Closed)
Patch Set: 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 | « no previous file | base/task_scheduler/task_scheduler_impl.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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 const SchedulerWorkerPoolParams& 54 const SchedulerWorkerPoolParams&
55 foreground_blocking_worker_pool_params_in); 55 foreground_blocking_worker_pool_params_in);
56 ~InitParams(); 56 ~InitParams();
57 57
58 const SchedulerWorkerPoolParams background_worker_pool_params; 58 const SchedulerWorkerPoolParams background_worker_pool_params;
59 const SchedulerWorkerPoolParams background_blocking_worker_pool_params; 59 const SchedulerWorkerPoolParams background_blocking_worker_pool_params;
60 const SchedulerWorkerPoolParams foreground_worker_pool_params; 60 const SchedulerWorkerPoolParams foreground_worker_pool_params;
61 const SchedulerWorkerPoolParams foreground_blocking_worker_pool_params; 61 const SchedulerWorkerPoolParams foreground_blocking_worker_pool_params;
62 }; 62 };
63 63
64 enum class SingleThreadTaskRunnerThreadMode {
fdoray 2017/05/10 12:32:23 Declare this in a separate file, so that post_task
gab 2017/05/10 15:20:47 Agreed, feels like this belongs in task_traits.h o
robliao 2017/05/11 05:30:12 Went with a new file. This isn't really part of Ta
65 // Allow the SingleThreadTaskRunner's thread to be shared with others,
66 // allowing for efficient use of thread resources when this
67 // SingleThreadTaskRunner is idle. This is the default mode and is
68 // recommended for most code.
69 SHARED,
70 // Dedicate a single thread for this SingleThreadTaskRunner. No other tasks
71 // from any other source will be scheduled on the thread backing
72 // the SingleThreadTaskRunner. Use sparingly as this reserves an entire
73 // thread for this SingleThreadTaskRunner.
74 DEDICATED,
75 };
76
64 // Destroying a TaskScheduler is not allowed in production; it is always 77 // Destroying a TaskScheduler is not allowed in production; it is always
65 // leaked. In tests, it should only be destroyed after JoinForTesting() has 78 // leaked. In tests, it should only be destroyed after JoinForTesting() has
66 // returned. 79 // returned.
67 virtual ~TaskScheduler() = default; 80 virtual ~TaskScheduler() = default;
68 81
69 // Allows the task scheduler to create threads and run tasks following the 82 // Allows the task scheduler to create threads and run tasks following the
70 // |init_params| specification. CHECKs on failure. 83 // |init_params| specification. CHECKs on failure.
71 virtual void Start(const InitParams& init_params) = 0; 84 virtual void Start(const InitParams& init_params) = 0;
72 85
73 // Posts |task| with a |delay| and specific |traits|. |delay| can be zero. 86 // Posts |task| with a |delay| and specific |traits|. |delay| can be zero.
(...skipping 11 matching lines...) Expand all
85 98
86 // Returns a SequencedTaskRunner whose PostTask invocations result in 99 // Returns a SequencedTaskRunner whose PostTask invocations result in
87 // scheduling tasks using |traits|. Tasks run one at a time in posting order. 100 // scheduling tasks using |traits|. Tasks run one at a time in posting order.
88 virtual scoped_refptr<SequencedTaskRunner> 101 virtual scoped_refptr<SequencedTaskRunner>
89 CreateSequencedTaskRunnerWithTraits(const TaskTraits& traits) = 0; 102 CreateSequencedTaskRunnerWithTraits(const TaskTraits& traits) = 0;
90 103
91 // Returns a SingleThreadTaskRunner whose PostTask invocations result in 104 // Returns a SingleThreadTaskRunner whose PostTask invocations result in
92 // scheduling tasks using |traits|. Tasks run on a single thread in posting 105 // scheduling tasks using |traits|. Tasks run on a single thread in posting
93 // order. 106 // order.
94 virtual scoped_refptr<SingleThreadTaskRunner> 107 virtual scoped_refptr<SingleThreadTaskRunner>
95 CreateSingleThreadTaskRunnerWithTraits(const TaskTraits& traits) = 0; 108 CreateSingleThreadTaskRunnerWithTraits(
109 const TaskTraits& traits,
110 SingleThreadTaskRunnerThreadMode thread_mode =
111 SingleThreadTaskRunnerThreadMode::SHARED) = 0;
96 112
97 #if defined(OS_WIN) 113 #if defined(OS_WIN)
98 // Returns a SingleThreadTaskRunner whose PostTask invocations result in 114 // Returns a SingleThreadTaskRunner whose PostTask invocations result in
99 // scheduling tasks using |traits| in a COM Single-Threaded Apartment. Tasks 115 // scheduling tasks using |traits| in a COM Single-Threaded Apartment. Tasks
100 // run in the same Single-Threaded Apartment in posting order for the returned 116 // run in the same Single-Threaded Apartment in posting order for the returned
101 // SingleThreadTaskRunner. There is not necessarily a one-to-one 117 // SingleThreadTaskRunner. There is not necessarily a one-to-one
102 // correspondence between SingleThreadTaskRunners and Single-Threaded 118 // correspondence between SingleThreadTaskRunners and Single-Threaded
103 // Apartments. The implementation is free to share apartments or create new 119 // Apartments. The implementation is free to share apartments or create new
104 // apartments as necessary. In either case, care should be taken to make sure 120 // apartments as necessary. In either case, care should be taken to make sure
105 // COM pointers are not smuggled across apartments. 121 // COM pointers are not smuggled across apartments.
106 virtual scoped_refptr<SingleThreadTaskRunner> 122 virtual scoped_refptr<SingleThreadTaskRunner>
107 CreateCOMSTATaskRunnerWithTraits(const TaskTraits& traits) = 0; 123 CreateCOMSTATaskRunnerWithTraits(
124 const TaskTraits& traits,
125 SingleThreadTaskRunnerThreadMode thread_mode =
126 SingleThreadTaskRunnerThreadMode::SHARED) = 0;
108 #endif // defined(OS_WIN) 127 #endif // defined(OS_WIN)
109 128
110 // Returns a vector of all histograms available in this task scheduler. 129 // Returns a vector of all histograms available in this task scheduler.
111 virtual std::vector<const HistogramBase*> GetHistograms() const = 0; 130 virtual std::vector<const HistogramBase*> GetHistograms() const = 0;
112 131
113 // Synchronously shuts down the scheduler. Once this is called, only tasks 132 // Synchronously shuts down the scheduler. Once this is called, only tasks
114 // posted with the BLOCK_SHUTDOWN behavior will be run. When this returns: 133 // posted with the BLOCK_SHUTDOWN behavior will be run. When this returns:
115 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their 134 // - All SKIP_ON_SHUTDOWN tasks that were already running have completed their
116 // execution. 135 // execution.
117 // - All posted BLOCK_SHUTDOWN tasks have completed their execution. 136 // - All posted BLOCK_SHUTDOWN tasks have completed their execution.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items. 215 // each process n/GetMaxConcurrentTasksWithTraitsDeprecated() items.
197 // 216 //
198 // TODO(fdoray): Remove this method. https://crbug.com/687264 217 // TODO(fdoray): Remove this method. https://crbug.com/687264
199 virtual int GetMaxConcurrentTasksWithTraitsDeprecated( 218 virtual int GetMaxConcurrentTasksWithTraitsDeprecated(
200 const TaskTraits& traits) const = 0; 219 const TaskTraits& traits) const = 0;
201 }; 220 };
202 221
203 } // namespace base 222 } // namespace base
204 223
205 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_ 224 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_H_
OLDNEW
« no previous file with comments | « no previous file | base/task_scheduler/task_scheduler_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698