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

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

Issue 1424053002: Adds a flag to support "Virtual Time" to the blink scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased 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 16 matching lines...) Expand all
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; 33 class LazyNow;
34 class TaskQueueImpl; 34 class TaskQueueImpl;
35 } // namespace internal 35 } // namespace internal
36 36
37 class NestableSingleThreadTaskRunner; 37 class TaskQueueManagerDelegate;
38 38
39 // The task queue manager provides N task queues and a selector interface for 39 // 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 40 // choosing which task queue to service next. Each task queue consists of two
41 // sub queues: 41 // sub queues:
42 // 42 //
43 // 1. Incoming task queue. Tasks that are posted get immediately appended here. 43 // 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 44 // 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. 45 // work function (DoWork) is scheduled to run on the main task runner.
46 // 46 //
47 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from 47 // 2. Work queue. If a work queue is empty when DoWork() is entered, tasks from
48 // the incoming task queue (if any) are moved here. The work queues are 48 // the incoming task queue (if any) are moved here. The work queues are
49 // registered with the selector as input to the scheduling decision. 49 // registered with the selector as input to the scheduling decision.
50 // 50 //
51 class SCHEDULER_EXPORT TaskQueueManager 51 class SCHEDULER_EXPORT TaskQueueManager
52 : public internal::TaskQueueSelector::Observer { 52 : public internal::TaskQueueSelector::Observer {
53 public: 53 public:
54 // Create a task queue manager where |main_task_runner| identifies the thread 54 // Create a task queue manager where |delegate| identifies the thread
55 // on which where the tasks are eventually run. Category strings must have 55 // on which where the tasks are eventually run. Category strings must have
56 // application lifetime (statics or literals). They may not include " chars. 56 // application lifetime (statics or literals). They may not include " chars.
57 TaskQueueManager( 57 TaskQueueManager(scoped_refptr<TaskQueueManagerDelegate> delegate,
58 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner, 58 const char* tracing_category,
59 const char* tracing_category, 59 const char* disabled_by_default_tracing_category,
60 const char* disabled_by_default_tracing_category, 60 const char* disabled_by_default_verbose_tracing_category);
61 const char* disabled_by_default_verbose_tracing_category);
62 ~TaskQueueManager() override; 61 ~TaskQueueManager() override;
63 62
64 // Returns the time of the next pending delayed task in any queue. Ignores 63 // Returns the time of the next pending delayed task in any queue. Ignores
65 // any delayed tasks whose delay has expired. Returns a null TimeTicks object 64 // any delayed tasks whose delay has expired. Returns a null TimeTicks object
66 // if no tasks are pending. NOTE this is somewhat expensive since every queue 65 // if no tasks are pending. NOTE this is somewhat expensive since every queue
67 // will get locked. 66 // will get locked.
68 base::TimeTicks NextPendingDelayedTaskRunTime(); 67 base::TimeTicks NextPendingDelayedTaskRunTime();
69 68
70 // Set the number of tasks executed in a single invocation of the task queue 69 // Set the number of tasks executed in a single invocation of the task queue
71 // manager. Increasing the batch size can reduce the overhead of yielding 70 // manager. Increasing the batch size can reduce the overhead of yielding
72 // back to the main message loop -- at the cost of potentially delaying other 71 // back to the main message loop -- at the cost of potentially delaying other
73 // tasks posted to the main loop. The batch size is 1 by default. 72 // tasks posted to the main loop. The batch size is 1 by default.
74 void SetWorkBatchSize(int work_batch_size); 73 void SetWorkBatchSize(int work_batch_size);
75 74
76 // These functions can only be called on the same thread that the task queue 75 // These functions can only be called on the same thread that the task queue
77 // manager executes its tasks on. 76 // manager executes its tasks on.
78 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer); 77 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer);
79 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer); 78 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer);
80 79
81 void SetTimeSourceForTesting(scoped_ptr<base::TickClock> time_source);
82
83 // Returns true if any task from a monitored task queue was was run since the 80 // Returns true if any task from a monitored task queue was was run since the
84 // last call to GetAndClearSystemIsQuiescentBit. 81 // last call to GetAndClearSystemIsQuiescentBit.
85 bool GetAndClearSystemIsQuiescentBit(); 82 bool GetAndClearSystemIsQuiescentBit();
86 83
87 // Creates a task queue with the given |spec|. Must be called on the thread 84 // Creates a task queue with the given |spec|. Must be called on the thread
88 // this class was created on. 85 // this class was created on.
89 scoped_refptr<internal::TaskQueueImpl> NewTaskQueue( 86 scoped_refptr<internal::TaskQueueImpl> NewTaskQueue(
90 const TaskQueue::Spec& spec); 87 const TaskQueue::Spec& spec);
91 88
92 class SCHEDULER_EXPORT Observer { 89 class SCHEDULER_EXPORT Observer {
93 public: 90 public:
94 virtual ~Observer() {} 91 virtual ~Observer() {}
95 92
96 // Called when |queue| is unregistered. 93 // Called when |queue| is unregistered.
97 virtual void OnUnregisterTaskQueue( 94 virtual void OnUnregisterTaskQueue(
98 const scoped_refptr<internal::TaskQueueImpl>& queue) = 0; 95 const scoped_refptr<internal::TaskQueueImpl>& queue) = 0;
99 }; 96 };
100 97
101 // Called once to set the Observer. This function is called on the main 98 // Called once to set the Observer. This function is called on the main
102 // thread. If |observer| is null, then no callbacks will occur. 99 // thread. If |observer| is null, then no callbacks will occur.
103 // Note |observer| is expected to outlive the SchedulerHelper. 100 // Note |observer| is expected to outlive the SchedulerHelper.
104 void SetObserver(Observer* observer); 101 void SetObserver(Observer* observer);
105 102
103 // Returns the TickClock used by the TaskQueueManager.
104 base::TickClock* tick_clock() const;
105
106 private: 106 private:
107 friend class internal::LazyNow; 107 friend class internal::LazyNow;
108 friend class internal::TaskQueueImpl; 108 friend class internal::TaskQueueImpl;
109 friend class TaskQueueManagerTest; 109 friend class TaskQueueManagerTest;
110 110
111 class DeletionSentinel : public base::RefCounted<DeletionSentinel> { 111 class DeletionSentinel : public base::RefCounted<DeletionSentinel> {
112 private: 112 private:
113 friend class base::RefCounted<DeletionSentinel>; 113 friend class base::RefCounted<DeletionSentinel>;
114 ~DeletionSentinel() {} 114 ~DeletionSentinel() {}
115 }; 115 };
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 enum class ProcessTaskResult { 153 enum class ProcessTaskResult {
154 DEFERRED, 154 DEFERRED,
155 EXECUTED, 155 EXECUTED,
156 TASK_QUEUE_MANAGER_DELETED 156 TASK_QUEUE_MANAGER_DELETED
157 }; 157 };
158 ProcessTaskResult ProcessTaskFromWorkQueue( 158 ProcessTaskResult ProcessTaskFromWorkQueue(
159 internal::TaskQueueImpl* queue, 159 internal::TaskQueueImpl* queue,
160 internal::TaskQueueImpl::Task* out_previous_task); 160 internal::TaskQueueImpl::Task* out_previous_task);
161 161
162 bool RunsTasksOnCurrentThread() const; 162 bool RunsTasksOnCurrentThread() const;
163 bool PostDelayedTask(const tracked_objects::Location& from_here,
164 const base::Closure& task,
165 base::TimeDelta delay);
166 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 163 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
167 const base::Closure& task, 164 const base::Closure& task,
168 base::TimeDelta delay); 165 base::TimeDelta delay);
169 166
170 base::TimeTicks Now() const;
171
172 int GetNextSequenceNumber(); 167 int GetNextSequenceNumber();
173 168
174 scoped_refptr<base::trace_event::ConvertableToTraceFormat> 169 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
175 AsValueWithSelectorResult(bool should_run, 170 AsValueWithSelectorResult(bool should_run,
176 internal::TaskQueueImpl* selected_queue) const; 171 internal::TaskQueueImpl* selected_queue) const;
177 172
178 // Causes DoWork to start calling UpdateWorkQueue for |queue|. Can be called 173 // Causes DoWork to start calling UpdateWorkQueue for |queue|. Can be called
179 // from any thread. 174 // from any thread.
180 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); 175 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue);
181 176
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 212
218 typedef std::multimap<base::TimeTicks, internal::TaskQueueImpl*> 213 typedef std::multimap<base::TimeTicks, internal::TaskQueueImpl*>
219 DelayedWakeupMultimap; 214 DelayedWakeupMultimap;
220 215
221 DelayedWakeupMultimap delayed_wakeup_multimap_; 216 DelayedWakeupMultimap delayed_wakeup_multimap_;
222 217
223 base::AtomicSequenceNumber task_sequence_num_; 218 base::AtomicSequenceNumber task_sequence_num_;
224 base::debug::TaskAnnotator task_annotator_; 219 base::debug::TaskAnnotator task_annotator_;
225 220
226 base::ThreadChecker main_thread_checker_; 221 base::ThreadChecker main_thread_checker_;
227 scoped_refptr<NestableSingleThreadTaskRunner> main_task_runner_; 222 scoped_refptr<TaskQueueManagerDelegate> delegate_;
228 internal::TaskQueueSelector selector_; 223 internal::TaskQueueSelector selector_;
229 224
230 base::Closure decrement_pending_and_do_work_closure_; 225 base::Closure decrement_pending_and_do_work_closure_;
231 base::Closure do_work_closure_; 226 base::Closure do_work_closure_;
232 227
233 bool task_was_run_on_quiescence_monitored_queue_; 228 bool task_was_run_on_quiescence_monitored_queue_;
234 229
235 // The pending_dowork_count_ is only tracked on the main thread since that's 230 // The pending_dowork_count_ is only tracked on the main thread since that's
236 // where re-entrant problems happen. 231 // where re-entrant problems happen.
237 int pending_dowork_count_; 232 int pending_dowork_count_;
238 233
239 int work_batch_size_; 234 int work_batch_size_;
240 235
241 scoped_ptr<base::TickClock> time_source_;
242
243 base::ObserverList<base::MessageLoop::TaskObserver> task_observers_; 236 base::ObserverList<base::MessageLoop::TaskObserver> task_observers_;
244 237
245 const char* tracing_category_; 238 const char* tracing_category_;
246 const char* disabled_by_default_tracing_category_; 239 const char* disabled_by_default_tracing_category_;
247 const char* disabled_by_default_verbose_tracing_category_; 240 const char* disabled_by_default_verbose_tracing_category_;
248 241
249 Observer* observer_; // NOT OWNED 242 Observer* observer_; // NOT OWNED
250 scoped_refptr<DeletionSentinel> deletion_sentinel_; 243 scoped_refptr<DeletionSentinel> deletion_sentinel_;
251 base::WeakPtrFactory<TaskQueueManager> weak_factory_; 244 base::WeakPtrFactory<TaskQueueManager> weak_factory_;
252 245
253 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); 246 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager);
254 }; 247 };
255 248
256 } // namespace scheduler 249 } // namespace scheduler
257 250
258 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_ 251 #endif // CONTENT_RENDERER_SCHEDULER_BASE_TASK_QUEUE_MANAGER_H_
OLDNEW
« no previous file with comments | « components/scheduler/base/task_queue_impl.cc ('k') | components/scheduler/base/task_queue_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698