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

Side by Side Diff: components/scheduler/base/task_queue_impl.h

Issue 1432263002: (reland) Adds TimeDomains to the TaskQueueManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing some more feedback. Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ 5 #ifndef CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_
6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ 6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/pending_task.h" 10 #include "base/pending_task.h"
11 #include "base/threading/thread_checker.h" 11 #include "base/threading/thread_checker.h"
12 #include "base/trace_event/trace_event.h" 12 #include "base/trace_event/trace_event.h"
13 #include "base/trace_event/trace_event_argument.h" 13 #include "base/trace_event/trace_event_argument.h"
14 #include "components/scheduler/base/lazy_now.h"
15 #include "components/scheduler/base/task_queue.h" 14 #include "components/scheduler/base/task_queue.h"
16 #include "components/scheduler/scheduler_export.h" 15 #include "components/scheduler/scheduler_export.h"
17 16
18 namespace scheduler { 17 namespace scheduler {
18 class LazyNow;
19 class TimeDomain;
19 class TaskQueueManager; 20 class TaskQueueManager;
20 21
21 namespace internal { 22 namespace internal {
22
23 class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue { 23 class SCHEDULER_EXPORT TaskQueueImpl final : public TaskQueue {
24 public: 24 public:
25 TaskQueueImpl(TaskQueueManager* task_queue_manager, 25 TaskQueueImpl(TaskQueueManager* task_queue_manager,
26 const scoped_refptr<TimeDomain>& time_domain,
26 const Spec& spec, 27 const Spec& spec,
27 const char* disabled_by_default_tracing_category, 28 const char* disabled_by_default_tracing_category,
28 const char* disabled_by_default_verbose_tracing_category); 29 const char* disabled_by_default_verbose_tracing_category);
29 30
30 class SCHEDULER_EXPORT Task : public base::PendingTask { 31 class SCHEDULER_EXPORT Task : public base::PendingTask {
31 public: 32 public:
32 Task(); 33 Task();
33 Task(const tracked_objects::Location& posted_from, 34 Task(const tracked_objects::Location& posted_from,
34 const base::Closure& task, 35 const base::Closure& task,
35 int sequence_number, 36 int sequence_number,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 bool GetQuiescenceMonitored() const { return should_monitor_quiescence_; } 118 bool GetQuiescenceMonitored() const { return should_monitor_quiescence_; }
118 bool GetShouldNotifyObservers() const { 119 bool GetShouldNotifyObservers() const {
119 return should_notify_observers_; 120 return should_notify_observers_;
120 } 121 }
121 122
122 void NotifyWillProcessTask(const base::PendingTask& pending_task); 123 void NotifyWillProcessTask(const base::PendingTask& pending_task);
123 void NotifyDidProcessTask(const base::PendingTask& pending_task); 124 void NotifyDidProcessTask(const base::PendingTask& pending_task);
124 125
125 // Delayed task posted to the underlying run loop, which locks 126 // Delayed task posted to the underlying run loop, which locks
126 // |any_thread_lock_| and calls MoveReadyDelayedTasksToIncomingQueueLocked to 127 // |any_thread_lock_| and calls MoveReadyDelayedTasksToIncomingQueueLocked to
127 // process dealyed tasks 128 // process dealyed tasks that need to be run now. Thread safe, but in
128 // that need to be run now. Thread safe, but in practice it's always called 129 // practice it's always called from the main thread.
129 // from the main thread.
130 void MoveReadyDelayedTasksToIncomingQueue(LazyNow* lazy_now); 130 void MoveReadyDelayedTasksToIncomingQueue(LazyNow* lazy_now);
131 131
132 // Test support functions. These should not be used in production code. 132 // Test support functions. These should not be used in production code.
133 void PushTaskOntoWorkQueueForTest(const Task& task); 133 void PushTaskOntoWorkQueueForTest(const Task& task);
134 void PopTaskFromWorkQueueForTest(); 134 void PopTaskFromWorkQueueForTest();
135 size_t WorkQueueSizeForTest() const { 135 size_t WorkQueueSizeForTest() const {
136 return main_thread_only().work_queue.size(); 136 return main_thread_only().work_queue.size();
137 } 137 }
138 size_t IncomingQueueSizeForTest() const;
138 139
139 // Can be called on any thread. 140 // Can be called on any thread.
140 static const char* PumpPolicyToString(TaskQueue::PumpPolicy pump_policy); 141 static const char* PumpPolicyToString(TaskQueue::PumpPolicy pump_policy);
141 142
142 // Can be called on any thread. 143 // Can be called on any thread.
143 static const char* WakeupPolicyToString( 144 static const char* WakeupPolicyToString(
144 TaskQueue::WakeupPolicy wakeup_policy); 145 TaskQueue::WakeupPolicy wakeup_policy);
145 146
146 // Can be called on any thread. 147 // Can be called on any thread.
147 static const char* PriorityToString(TaskQueue::QueuePriority priority); 148 static const char* PriorityToString(TaskQueue::QueuePriority priority);
148 149
149 private: 150 private:
150 enum class TaskType { 151 enum class TaskType {
151 NORMAL, 152 NORMAL,
152 NON_NESTABLE, 153 NON_NESTABLE,
153 }; 154 };
154 155
155 struct AnyThread { 156 struct AnyThread {
156 AnyThread(TaskQueueManager* task_queue_manager, PumpPolicy pump_policy); 157 AnyThread(TaskQueueManager* task_queue_manager,
158 PumpPolicy pump_policy,
159 const scoped_refptr<TimeDomain>& time_domain);
157 ~AnyThread(); 160 ~AnyThread();
158 161
159 // TaskQueueManager is maintained in two copies: inside AnyThread and inside 162 // TaskQueueManager is maintained in two copies: inside AnyThread and inside
160 // MainThreadOnly. It can be changed only from main thread, so it should be 163 // MainThreadOnly. It can be changed only from main thread, so it should be
161 // locked before accessing from other threads. 164 // locked before accessing from other threads.
162 TaskQueueManager* task_queue_manager; 165 TaskQueueManager* task_queue_manager;
163 166
164 std::queue<Task> incoming_queue; 167 std::queue<Task> incoming_queue;
165 PumpPolicy pump_policy; 168 PumpPolicy pump_policy;
166 std::priority_queue<Task> delayed_task_queue; 169 std::priority_queue<Task> delayed_task_queue;
170 scoped_refptr<TimeDomain> time_domain;
167 }; 171 };
168 172
169 struct MainThreadOnly { 173 struct MainThreadOnly {
170 explicit MainThreadOnly(TaskQueueManager* task_queue_manager); 174 explicit MainThreadOnly(TaskQueueManager* task_queue_manager);
171 ~MainThreadOnly(); 175 ~MainThreadOnly();
172 176
173 // Another copy of TaskQueueManager for lock-free access from the main 177 // Another copy of TaskQueueManager for lock-free access from the main
174 // thread. See description inside struct AnyThread for details. 178 // thread. See description inside struct AnyThread for details.
175 TaskQueueManager* task_queue_manager; 179 TaskQueueManager* task_queue_manager;
176 180
177 std::queue<Task> work_queue; 181 std::queue<Task> work_queue;
178 base::ObserverList<base::MessageLoop::TaskObserver> task_observers; 182 base::ObserverList<base::MessageLoop::TaskObserver> task_observers;
179 size_t set_index; 183 size_t set_index;
180 }; 184 };
181 185
182 ~TaskQueueImpl() override; 186 ~TaskQueueImpl() override;
183 187
184 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here, 188 bool PostDelayedTaskImpl(const tracked_objects::Location& from_here,
185 const base::Closure& task, 189 const base::Closure& task,
186 base::TimeDelta delay, 190 base::TimeDelta delay,
187 TaskType task_type); 191 TaskType task_type);
188 bool PostDelayedTaskLocked(LazyNow* lazy_now, 192 bool PostDelayedTaskLocked(LazyNow* lazy_now,
189 const tracked_objects::Location& from_here, 193 const tracked_objects::Location& from_here,
190 const base::Closure& task, 194 const base::Closure& task,
191 base::TimeTicks desired_run_time, 195 base::TimeTicks desired_run_time,
192 TaskType task_type); 196 TaskType task_type);
193 197
194 // Enqueues any delayed tasks which should be run now on the incoming_queue_ 198 // Enqueues any delayed tasks which should be run now on the incoming_queue_.
195 // and calls ScheduleDelayedWorkLocked to ensure future tasks are scheduled.
196 // Must be called with |any_thread_lock_| locked. 199 // Must be called with |any_thread_lock_| locked.
197 void MoveReadyDelayedTasksToIncomingQueueLocked(LazyNow* lazy_now); 200 void MoveReadyDelayedTasksToIncomingQueueLocked(LazyNow* lazy_now);
198 201
199 void PumpQueueLocked(); 202 void PumpQueueLocked();
200 bool TaskIsOlderThanQueuedTasks(const Task* task); 203 bool TaskIsOlderThanQueuedTasks(const Task* task);
201 bool ShouldAutoPumpQueueLocked(bool should_trigger_wakeup, 204 bool ShouldAutoPumpQueueLocked(bool should_trigger_wakeup,
202 const Task* previous_task); 205 const Task* previous_task);
203 206
204 // Push the task onto the |incoming_queue_| and for auto pumped queues it 207 // Push the task onto the |incoming_queue_| and for auto pumped queues it
205 // calls MaybePostDoWorkOnMainRunner if the incomming queue was empty. 208 // calls MaybePostDoWorkOnMainRunner if the incomming queue was empty.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 const bool should_monitor_quiescence_; 253 const bool should_monitor_quiescence_;
251 const bool should_notify_observers_; 254 const bool should_notify_observers_;
252 255
253 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl); 256 DISALLOW_COPY_AND_ASSIGN(TaskQueueImpl);
254 }; 257 };
255 258
256 } // namespace internal 259 } // namespace internal
257 } // namespace scheduler 260 } // namespace scheduler
258 261
259 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_ 262 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698