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

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

Issue 1432263002: (reland) Adds TimeDomains to the TaskQueueManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Forgot to change VirtualTimeDomain::GetName 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_MANAGER_H_ 5 #ifndef CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_
6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ 6 #define CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/atomic_sequence_num.h" 10 #include "base/atomic_sequence_num.h"
(...skipping 12 matching lines...) Expand all
23 class TickClock; 23 class TickClock;
24 24
25 namespace trace_event { 25 namespace trace_event {
26 class ConvertableToTraceFormat; 26 class ConvertableToTraceFormat;
27 class TracedValue; 27 class TracedValue;
28 } // namespace trace_event 28 } // namespace trace_event
29 } // namespace base 29 } // namespace base
30 30
31 namespace scheduler { 31 namespace scheduler {
32 namespace internal { 32 namespace internal {
33 class LazyNow;
34 class TaskQueueImpl; 33 class TaskQueueImpl;
35 } // namespace internal 34 } // namespace internal
36 35
36 class LazyNow;
37 class RealTimeDomain;
38 class TimeDomain;
37 class TaskQueueManagerDelegate; 39 class TaskQueueManagerDelegate;
38 40
39 // The task queue manager provides N task queues and a selector interface for 41 // The task queue manager provides N task queues and a selector interface for
40 // choosing which task queue to service next. Each task queue consists of two 42 // choosing which task queue to service next. Each task queue consists of two
41 // sub queues: 43 // sub queues:
42 // 44 //
43 // 1. Incoming task queue. Tasks that are posted get immediately appended here. 45 // 1. Incoming task queue. Tasks that are posted get immediately appended here.
44 // When a task is appended into an empty incoming queue, the task manager 46 // When a task is appended into an empty incoming queue, the task manager
45 // work function (DoWork) is scheduled to run on the main task runner. 47 // work function (DoWork) is scheduled to run on the main task runner.
46 // 48 //
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 }; 98 };
97 99
98 // Called once to set the Observer. This function is called on the main 100 // Called once to set the Observer. This function is called on the main
99 // thread. If |observer| is null, then no callbacks will occur. 101 // thread. If |observer| is null, then no callbacks will occur.
100 // Note |observer| is expected to outlive the SchedulerHelper. 102 // Note |observer| is expected to outlive the SchedulerHelper.
101 void SetObserver(Observer* observer); 103 void SetObserver(Observer* observer);
102 104
103 // Returns the delegate used by the TaskQueueManager. 105 // Returns the delegate used by the TaskQueueManager.
104 const scoped_refptr<TaskQueueManagerDelegate>& delegate() const; 106 const scoped_refptr<TaskQueueManagerDelegate>& delegate() const;
105 107
108 // Time domains must be registered for the task queues to get updated.
109 void RegisterTimeDomain(const scoped_refptr<TimeDomain>& time_domain);
110 void UnregisterTimeDomain(const scoped_refptr<TimeDomain>& time_domain);
111
112 const scoped_refptr<RealTimeDomain>& real_time_domain() const {
113 return real_time_domain_;
114 }
115
106 private: 116 private:
107 friend class internal::LazyNow; 117 friend class LazyNow;
108 friend class internal::TaskQueueImpl; 118 friend class internal::TaskQueueImpl;
109 friend class TaskQueueManagerTest; 119 friend class TaskQueueManagerTest;
110 120
111 class DeletionSentinel : public base::RefCounted<DeletionSentinel> { 121 class DeletionSentinel : public base::RefCounted<DeletionSentinel> {
112 private: 122 private:
113 friend class base::RefCounted<DeletionSentinel>; 123 friend class base::RefCounted<DeletionSentinel>;
114 ~DeletionSentinel() {} 124 ~DeletionSentinel() {}
115 }; 125 };
116 126
117 // Unregisters a TaskQueue previously created by |NewTaskQueue()|. 127 // Unregisters a TaskQueue previously created by |NewTaskQueue()|.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 internal::TaskQueueImpl* queue, 169 internal::TaskQueueImpl* queue,
160 internal::TaskQueueImpl::Task* out_previous_task); 170 internal::TaskQueueImpl::Task* out_previous_task);
161 171
162 bool RunsTasksOnCurrentThread() const; 172 bool RunsTasksOnCurrentThread() const;
163 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 173 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
164 const base::Closure& task, 174 const base::Closure& task,
165 base::TimeDelta delay); 175 base::TimeDelta delay);
166 176
167 int GetNextSequenceNumber(); 177 int GetNextSequenceNumber();
168 178
179 bool ATimeDomainCanAdvance();
Sami 2015/11/19 13:01:03 nit: the name makes this sound like an idempotent
alex clarke (OOO till 29th) 2015/11/19 13:54:48 Done.
180
169 scoped_refptr<base::trace_event::ConvertableToTraceFormat> 181 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
170 AsValueWithSelectorResult(bool should_run, 182 AsValueWithSelectorResult(bool should_run,
171 internal::TaskQueueImpl* selected_queue) const; 183 internal::TaskQueueImpl* selected_queue) const;
172 184
173 // Causes DoWork to start calling UpdateWorkQueue for |queue|. Can be called 185 std::set<scoped_refptr<TimeDomain>> time_domains_;
174 // from any thread. 186 scoped_refptr<RealTimeDomain> real_time_domain_;
175 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue);
176
177 // Prevents DoWork from calling UpdateWorkQueue for |queue|. Must be called
178 // from the thread the TaskQueueManager was created on.
179 void UnregisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue);
180
181 // Schedule a call to DoWork at |delayed_run_time| which indirectly calls
182 // TaskQueueImpl::MoveReadyDelayedTasksToIncomingQueue for |queue|.
183 // Can be called from any thread.
184 void ScheduleDelayedWork(internal::TaskQueueImpl* queue,
185 base::TimeTicks delayed_run_time,
186 internal::LazyNow* lazy_now);
187
188 // Function calling ScheduleDelayedWork that's suitable for use in base::Bind.
189 void ScheduleDelayedWorkTask(scoped_refptr<internal::TaskQueueImpl> queue,
190 base::TimeTicks delayed_run_time);
191
192 // Call TaskQueueImpl::MoveReadyDelayedTasksToIncomingQueue for each
193 // registered queue for which the delay has elapsed.
194 void WakeupReadyDelayedQueues(internal::LazyNow* lazy_now);
195
196 void MoveNewlyUpdatableQueuesIntoUpdatableQueueSet();
197 187
198 std::set<scoped_refptr<internal::TaskQueueImpl>> queues_; 188 std::set<scoped_refptr<internal::TaskQueueImpl>> queues_;
199 189
200 // We have to be careful when deleting a queue because some of the code uses 190 // We have to be careful when deleting a queue because some of the code uses
201 // raw pointers and doesn't expect the rug to be pulled out from underneath. 191 // raw pointers and doesn't expect the rug to be pulled out from underneath.
202 std::set<scoped_refptr<internal::TaskQueueImpl>> queues_to_delete_; 192 std::set<scoped_refptr<internal::TaskQueueImpl>> queues_to_delete_;
203 193
204 // This lock guards only |newly_updatable_|. It's not expected to be heavily
205 // contended.
206 base::Lock newly_updatable_lock_;
207 std::vector<internal::TaskQueueImpl*> newly_updatable_;
208
209 // Set of task queues with avaliable work on the incoming queue. This should
210 // only be accessed from the main thread.
211 std::set<internal::TaskQueueImpl*> updatable_queue_set_;
212
213 typedef std::multimap<base::TimeTicks, internal::TaskQueueImpl*>
214 DelayedWakeupMultimap;
215
216 DelayedWakeupMultimap delayed_wakeup_multimap_;
217 194
218 base::AtomicSequenceNumber task_sequence_num_; 195 base::AtomicSequenceNumber task_sequence_num_;
219 base::debug::TaskAnnotator task_annotator_; 196 base::debug::TaskAnnotator task_annotator_;
220 197
221 base::ThreadChecker main_thread_checker_; 198 base::ThreadChecker main_thread_checker_;
222 scoped_refptr<TaskQueueManagerDelegate> delegate_; 199 scoped_refptr<TaskQueueManagerDelegate> delegate_;
223 internal::TaskQueueSelector selector_; 200 internal::TaskQueueSelector selector_;
224 201
225 base::Closure decrement_pending_and_do_work_closure_; 202 base::Closure decrement_pending_and_do_work_closure_;
226 base::Closure do_work_closure_; 203 base::Closure do_work_closure_;
227 204
228 bool task_was_run_on_quiescence_monitored_queue_; 205 bool task_was_run_on_quiescence_monitored_queue_;
229 206
230 // The pending_dowork_count_ is only tracked on the main thread since that's 207 // The pending_dowork_count_ is only tracked on the main thread since that's
231 // where re-entrant problems happen. 208 // where re-entrant problems happen.
232 int pending_dowork_count_; 209 int pending_dowork_count_;
233 210
234 int work_batch_size_; 211 int work_batch_size_;
235 212
236 base::ObserverList<base::MessageLoop::TaskObserver> task_observers_; 213 base::ObserverList<base::MessageLoop::TaskObserver> task_observers_;
237 214
238 const char* tracing_category_; 215 const char* tracing_category_;
239 const char* disabled_by_default_tracing_category_; 216 const char* disabled_by_default_tracing_category_;
240 const char* disabled_by_default_verbose_tracing_category_; 217 const char* disabled_by_default_verbose_tracing_category_;
241 218
242 Observer* observer_; // NOT OWNED 219 Observer* observer_; // NOT OWNED
243 scoped_refptr<DeletionSentinel> deletion_sentinel_; 220 scoped_refptr<DeletionSentinel> deletion_sentinel_;
221 scoped_refptr<TimeDomain> time_domain_;
244 base::WeakPtrFactory<TaskQueueManager> weak_factory_; 222 base::WeakPtrFactory<TaskQueueManager> weak_factory_;
245 223
246 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); 224 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager);
247 }; 225 };
248 226
249 } // namespace scheduler 227 } // namespace scheduler
250 228
251 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ 229 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698