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

Side by Side Diff: content/renderer/scheduler/task_queue_manager.h

Issue 922733002: scheduler: Implement task observers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implemented Ross's simplification idea. Created 5 years, 10 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
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_TASK_QUEUE_MANAGER_H_ 5 #ifndef CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_
6 #define CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ 6 #define CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_
7 7
8 #include "base/atomic_sequence_num.h" 8 #include "base/atomic_sequence_num.h"
9 #include "base/debug/task_annotator.h" 9 #include "base/debug/task_annotator.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/message_loop/message_loop.h"
12 #include "base/pending_task.h" 13 #include "base/pending_task.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
15 #include "base/threading/thread_checker.h" 16 #include "base/threading/thread_checker.h"
16 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
17 18
18 namespace base { 19 namespace base {
19 namespace trace_event { 20 namespace trace_event {
20 class ConvertableToTraceFormat; 21 class ConvertableToTraceFormat;
21 class TracedValue; 22 class TracedValue;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // Set the name |queue_index| for tracing purposes. |name| must be a pointer 84 // Set the name |queue_index| for tracing purposes. |name| must be a pointer
84 // to a static string. 85 // to a static string.
85 void SetQueueName(size_t queue_index, const char* name); 86 void SetQueueName(size_t queue_index, const char* name);
86 87
87 // Set the number of tasks executed in a single invocation of the task queue 88 // Set the number of tasks executed in a single invocation of the task queue
88 // manager. Increasing the batch size can reduce the overhead of yielding 89 // manager. Increasing the batch size can reduce the overhead of yielding
89 // back to the main message loop -- at the cost of potentially delaying other 90 // back to the main message loop -- at the cost of potentially delaying other
90 // tasks posted to the main loop. The batch size is 1 by default. 91 // tasks posted to the main loop. The batch size is 1 by default.
91 void SetWorkBatchSize(int work_batch_size); 92 void SetWorkBatchSize(int work_batch_size);
92 93
94 // These functions can only be called on the same thread that the task queue
95 // manager executes its tasks on.
96 void AddTaskObserver(base::MessageLoop::TaskObserver* task_observer);
97 void RemoveTaskObserver(base::MessageLoop::TaskObserver* task_observer);
98
93 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source); 99 void SetTimeSourceForTesting(scoped_refptr<cc::TestNowSource> time_source);
94 100
95 private: 101 private:
96 friend class internal::TaskQueue; 102 friend class internal::TaskQueue;
97 103
98 // Called by the task queue to register a new pending task and allocate a 104 // Called by the task queue to register a new pending task and allocate a
99 // sequence number for it. 105 // sequence number for it.
100 void DidQueueTask(base::PendingTask* pending_task); 106 void DidQueueTask(base::PendingTask* pending_task);
101 107
102 // Post a task to call DoWork() on the main task runner. Only one pending 108 // Post a task to call DoWork() on the main task runner. Only one pending
103 // DoWork is allowed from the main thread, to prevent an explosion of pending 109 // DoWork is allowed from the main thread, to prevent an explosion of pending
104 // DoWorks. 110 // DoWorks.
105 void MaybePostDoWorkOnMainRunner(); 111 void MaybePostDoWorkOnMainRunner();
106 112
107 // Use the selector to choose a pending task and run it. 113 // Use the selector to choose a pending task and run it.
108 void DoWork(bool posted_from_main_thread); 114 void DoWork(bool posted_from_main_thread);
109 115
110 // Reloads any empty work queues which have automatic pumping enabled. 116 // Reloads any empty work queues which have automatic pumping enabled.
111 // Returns true if any work queue has tasks after doing this. 117 // Returns true if any work queue has tasks after doing this.
112 // |next_pending_delayed_task| should be the time of the next known delayed 118 // |next_pending_delayed_task| should be the time of the next known delayed
113 // task. It is updated if any task is found which should run earlier. 119 // task. It is updated if any task is found which should run earlier.
114 bool UpdateWorkQueues(base::TimeTicks* next_pending_delayed_task); 120 bool UpdateWorkQueues(base::TimeTicks* next_pending_delayed_task);
115 121
116 // Chooses the next work queue to service. Returns true if |out_queue_index| 122 // Chooses the next work queue to service. Returns true if |out_queue_index|
117 // indicates the queue from which the next task should be run, false to 123 // indicates the queue from which the next task should be run, false to
118 // avoid running any tasks. 124 // avoid running any tasks.
119 bool SelectWorkQueueToService(size_t* out_queue_index); 125 bool SelectWorkQueueToService(size_t* out_queue_index);
120 126
121 // Runs a single nestable task from the work queue designated by 127 // Runs a single nestable task from the work queue designated by
122 // |queue_index|. Non-nestable task are reposted on the run loop. 128 // |queue_index|. |first_task_in_batch| should be true if this the first task
123 // The queue must not be empty. 129 // we are executing in the current work batch. Non-nestable task are reposted
124 void ProcessTaskFromWorkQueue(size_t queue_index); 130 // on the run loop. The queue must not be empty.
131 void ProcessTaskFromWorkQueue(size_t queue_index, bool first_task_in_batch);
125 132
126 bool RunsTasksOnCurrentThread() const; 133 bool RunsTasksOnCurrentThread() const;
127 bool PostDelayedTask(const tracked_objects::Location& from_here, 134 bool PostDelayedTask(const tracked_objects::Location& from_here,
128 const base::Closure& task, 135 const base::Closure& task,
129 base::TimeDelta delay); 136 base::TimeDelta delay);
130 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, 137 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
131 const base::Closure& task, 138 const base::Closure& task,
132 base::TimeDelta delay); 139 base::TimeDelta delay);
133 internal::TaskQueue* Queue(size_t queue_index) const; 140 internal::TaskQueue* Queue(size_t queue_index) const;
134 141
(...skipping 13 matching lines...) Expand all
148 base::WeakPtr<TaskQueueManager> task_queue_manager_weak_ptr_; 155 base::WeakPtr<TaskQueueManager> task_queue_manager_weak_ptr_;
149 156
150 // The pending_dowork_count_ is only tracked on the main thread since that's 157 // The pending_dowork_count_ is only tracked on the main thread since that's
151 // where re-entrant problems happen. 158 // where re-entrant problems happen.
152 int pending_dowork_count_; 159 int pending_dowork_count_;
153 160
154 int work_batch_size_; 161 int work_batch_size_;
155 162
156 scoped_refptr<cc::TestNowSource> time_source_; 163 scoped_refptr<cc::TestNowSource> time_source_;
157 164
165 ObserverList<base::MessageLoop::TaskObserver> task_observers_;
166
167 // Previously executed task. Only valid during a call to DoWork().
168 base::PendingTask previous_task_;
169
158 base::WeakPtrFactory<TaskQueueManager> weak_factory_; 170 base::WeakPtrFactory<TaskQueueManager> weak_factory_;
159 171
160 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager); 172 DISALLOW_COPY_AND_ASSIGN(TaskQueueManager);
161 }; 173 };
162 174
163 } // namespace content 175 } // namespace content
164 176
165 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_ 177 #endif // CONTENT_RENDERER_SCHEDULER_TASK_QUEUE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698