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

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/base/time_domain.h

Issue 2640763003: Optimize away updatable_queue_set_ (Closed)
Patch Set: Fix lock issue plus rename OnPushQueue Created 3 years, 11 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 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 THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ 5 #ifndef THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_
6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ 6 #define THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 // Migrates |queue| from this time domain to |destination_time_domain|. 82 // Migrates |queue| from this time domain to |destination_time_domain|.
83 // Main-thread only. 83 // Main-thread only.
84 void MigrateQueue(internal::TaskQueueImpl* queue, 84 void MigrateQueue(internal::TaskQueueImpl* queue,
85 TimeDomain* destination_time_domain); 85 TimeDomain* destination_time_domain);
86 86
87 // If there is a scheduled delayed task, |out_task_queue| is set to the queue 87 // If there is a scheduled delayed task, |out_task_queue| is set to the queue
88 // the next task was posted to and it returns true. Returns false otherwise. 88 // the next task was posted to and it returns true. Returns false otherwise.
89 bool NextScheduledTaskQueue(TaskQueue** out_task_queue) const; 89 bool NextScheduledTaskQueue(TaskQueue** out_task_queue) const;
90 90
91 // Adds |queue| to the set of task queues that UpdateWorkQueues calls 91 // Adds |queue| to |has_incoming_immediate_work_| which causes
92 // UpdateWorkQueue on. 92 // UpdateWorkQueues to reload the immediate work queue if empty. Can be
93 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); 93 // called from any thread.
94 // TODO(alexclarke): Move this to the TaskQueueManager.
95 void OnQueueHasIncomingImmediateWork(internal::TaskQueueImpl* queue);
94 96
95 // Schedules a call to TaskQueueImpl::WakeUpForDelayedWork when this 97 // Schedules a call to TaskQueueImpl::WakeUpForDelayedWork when this
96 // TimeDomain reaches |delayed_run_time|. This supersedes any previously 98 // TimeDomain reaches |delayed_run_time|. This supersedes any previously
97 // registered wakeup for |queue|. 99 // registered wakeup for |queue|.
98 void ScheduleDelayedWork(internal::TaskQueueImpl* queue, 100 void ScheduleDelayedWork(internal::TaskQueueImpl* queue,
99 base::TimeTicks delayed_run_time, 101 base::TimeTicks delayed_run_time,
100 base::TimeTicks now); 102 base::TimeTicks now);
101 103
102 // Registers the |queue|. 104 // Registers the |queue|.
103 void RegisterQueue(internal::TaskQueueImpl* queue); 105 void RegisterQueue(internal::TaskQueueImpl* queue);
104 106
105 // Removes |queue| from the set of task queues that UpdateWorkQueues calls
106 // UpdateWorkQueue on. Returns true if |queue| was updatable.
107 bool UnregisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue);
108
109 // Removes |queue| from all internal data structures. 107 // Removes |queue| from all internal data structures.
110 void UnregisterQueue(internal::TaskQueueImpl* queue); 108 void UnregisterQueue(internal::TaskQueueImpl* queue);
111 109
112 // Updates active queues associated with this TimeDomain. 110 // Updates active queues associated with this TimeDomain.
113 void UpdateWorkQueues(LazyNow lazy_now); 111 void UpdateWorkQueues(LazyNow lazy_now);
114 112
115 // Called by the TaskQueueManager when the TimeDomain is registered. 113 // Called by the TaskQueueManager when the TimeDomain is registered.
116 virtual void OnRegisterWithTaskQueueManager( 114 virtual void OnRegisterWithTaskQueueManager(
117 TaskQueueManager* task_queue_manager) = 0; 115 TaskQueueManager* task_queue_manager) = 0;
118 116
(...skipping 10 matching lines...) Expand all
129 127
130 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay 128 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay
131 // has elapsed. 129 // has elapsed.
132 void WakeupReadyDelayedQueues(LazyNow* lazy_now); 130 void WakeupReadyDelayedQueues(LazyNow* lazy_now);
133 131
134 size_t NumberOfScheduledWakeups() const { 132 size_t NumberOfScheduledWakeups() const {
135 return delayed_wakeup_queue_.size(); 133 return delayed_wakeup_queue_.size();
136 } 134 }
137 135
138 private: 136 private:
139 void MoveNewlyUpdatableQueuesIntoUpdatableQueueSet();
140
141 struct DelayedWakeup { 137 struct DelayedWakeup {
142 base::TimeTicks time; 138 base::TimeTicks time;
143 internal::TaskQueueImpl* queue; 139 internal::TaskQueueImpl* queue;
144 140
145 bool operator<=(const DelayedWakeup& other) const { 141 bool operator<=(const DelayedWakeup& other) const {
146 if (time == other.time) 142 if (time == other.time)
147 return queue <= other.queue; 143 return queue <= other.queue;
148 return time < other.time; 144 return time < other.time;
149 } 145 }
150 146
151 void SetHeapHandle(HeapHandle handle) { 147 void SetHeapHandle(HeapHandle handle) {
152 DCHECK(handle.IsValid()); 148 DCHECK(handle.IsValid());
153 queue->set_heap_handle(handle); 149 queue->set_heap_handle(handle);
154 } 150 }
155 151
156 void ClearHeapHandle() { 152 void ClearHeapHandle() {
157 DCHECK(queue->heap_handle().IsValid()); 153 DCHECK(queue->heap_handle().IsValid());
158 queue->set_heap_handle(HeapHandle()); 154 queue->set_heap_handle(HeapHandle());
159 155
160 DCHECK_NE(queue->scheduled_time_domain_wakeup(), base::TimeTicks()); 156 DCHECK_NE(queue->scheduled_time_domain_wakeup(), base::TimeTicks());
161 queue->set_scheduled_time_domain_wakeup(base::TimeTicks()); 157 queue->set_scheduled_time_domain_wakeup(base::TimeTicks());
162 } 158 }
163 }; 159 };
164 160
165 IntrusiveHeap<DelayedWakeup> delayed_wakeup_queue_; 161 IntrusiveHeap<DelayedWakeup> delayed_wakeup_queue_;
166 162
167 // This lock guards only |newly_updatable_|. It's not expected to be heavily 163 // This lock guards only |has_incoming_immediate_work_|. It's not expected to
168 // contended. 164 // be heavily contended.
169 base::Lock newly_updatable_lock_; 165 mutable base::Lock has_incoming_immediate_work_lock_;
170 std::vector<internal::TaskQueueImpl*> newly_updatable_;
171 166
172 // Set of task queues with avaliable work on the incoming queue. This should 167 // Set of task queues with newly available work on the incoming queue.
173 // only be accessed from the main thread. 168 // TODO(alexclarke): Move this to the TaskQueueManager.
174 std::set<internal::TaskQueueImpl*> updatable_queue_set_; 169 std::set<internal::TaskQueueImpl*> has_incoming_immediate_work_;
175 170
176 Observer* observer_; // NOT OWNED. 171 Observer* observer_; // NOT OWNED.
177 172
178 base::ThreadChecker main_thread_checker_; 173 base::ThreadChecker main_thread_checker_;
179 174
180 DISALLOW_COPY_AND_ASSIGN(TimeDomain); 175 DISALLOW_COPY_AND_ASSIGN(TimeDomain);
181 }; 176 };
182 177
183 } // namespace scheduler 178 } // namespace scheduler
184 } // namespace blink 179 } // namespace blink
185 180
186 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ 181 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698