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

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

Issue 2640763003: Optimize away updatable_queue_set_ (Closed)
Patch Set: 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 the set of task queues that UpdateWorkQueues calls
Sami 2017/01/18 17:57:04 This comment looks out of date now. Also, could y
alex clarke (OOO till 29th) 2017/01/19 08:50:52 Done.
92 // UpdateWorkQueue on. 92 // UpdateWorkQueue on.
93 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue); 93 void OnQueueHasIncomingImmediateWork(internal::TaskQueueImpl* queue);
94 94
95 // Schedules a call to TaskQueueImpl::WakeUpForDelayedWork when this 95 // Schedules a call to TaskQueueImpl::WakeUpForDelayedWork when this
96 // TimeDomain reaches |delayed_run_time|. This supersedes any previously 96 // TimeDomain reaches |delayed_run_time|. This supersedes any previously
97 // registered wakeup for |queue|. 97 // registered wakeup for |queue|.
98 void ScheduleDelayedWork(internal::TaskQueueImpl* queue, 98 void ScheduleDelayedWork(internal::TaskQueueImpl* queue,
99 base::TimeTicks delayed_run_time, 99 base::TimeTicks delayed_run_time,
100 base::TimeTicks now); 100 base::TimeTicks now);
101 101
102 // Registers the |queue|. 102 // Registers the |queue|.
103 void RegisterQueue(internal::TaskQueueImpl* queue); 103 void RegisterQueue(internal::TaskQueueImpl* queue);
104 104
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. 105 // Removes |queue| from all internal data structures.
110 void UnregisterQueue(internal::TaskQueueImpl* queue); 106 void UnregisterQueue(internal::TaskQueueImpl* queue);
111 107
112 // Updates active queues associated with this TimeDomain. 108 // Updates active queues associated with this TimeDomain.
113 void UpdateWorkQueues(LazyNow lazy_now); 109 void UpdateWorkQueues(LazyNow lazy_now);
114 110
115 // Called by the TaskQueueManager when the TimeDomain is registered. 111 // Called by the TaskQueueManager when the TimeDomain is registered.
116 virtual void OnRegisterWithTaskQueueManager( 112 virtual void OnRegisterWithTaskQueueManager(
117 TaskQueueManager* task_queue_manager) = 0; 113 TaskQueueManager* task_queue_manager) = 0;
118 114
(...skipping 10 matching lines...) Expand all
129 125
130 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay 126 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay
131 // has elapsed. 127 // has elapsed.
132 void WakeupReadyDelayedQueues(LazyNow* lazy_now); 128 void WakeupReadyDelayedQueues(LazyNow* lazy_now);
133 129
134 size_t NumberOfScheduledWakeups() const { 130 size_t NumberOfScheduledWakeups() const {
135 return delayed_wakeup_queue_.size(); 131 return delayed_wakeup_queue_.size();
136 } 132 }
137 133
138 private: 134 private:
139 void MoveNewlyUpdatableQueuesIntoUpdatableQueueSet();
140
141 struct DelayedWakeup { 135 struct DelayedWakeup {
142 base::TimeTicks time; 136 base::TimeTicks time;
143 internal::TaskQueueImpl* queue; 137 internal::TaskQueueImpl* queue;
144 138
145 bool operator<=(const DelayedWakeup& other) const { 139 bool operator<=(const DelayedWakeup& other) const {
146 if (time == other.time) 140 if (time == other.time)
147 return queue <= other.queue; 141 return queue <= other.queue;
148 return time < other.time; 142 return time < other.time;
149 } 143 }
150 144
151 void SetHeapHandle(HeapHandle handle) { 145 void SetHeapHandle(HeapHandle handle) {
152 DCHECK(handle.IsValid()); 146 DCHECK(handle.IsValid());
153 queue->set_heap_handle(handle); 147 queue->set_heap_handle(handle);
154 } 148 }
155 149
156 void ClearHeapHandle() { 150 void ClearHeapHandle() {
157 DCHECK(queue->heap_handle().IsValid()); 151 DCHECK(queue->heap_handle().IsValid());
158 queue->set_heap_handle(HeapHandle()); 152 queue->set_heap_handle(HeapHandle());
159 153
160 DCHECK_NE(queue->scheduled_time_domain_wakeup(), base::TimeTicks()); 154 DCHECK_NE(queue->scheduled_time_domain_wakeup(), base::TimeTicks());
161 queue->set_scheduled_time_domain_wakeup(base::TimeTicks()); 155 queue->set_scheduled_time_domain_wakeup(base::TimeTicks());
162 } 156 }
163 }; 157 };
164 158
165 IntrusiveHeap<DelayedWakeup> delayed_wakeup_queue_; 159 IntrusiveHeap<DelayedWakeup> delayed_wakeup_queue_;
166 160
167 // This lock guards only |newly_updatable_|. It's not expected to be heavily 161 // This lock guards only |has_incoming_immediate_work_|. It's not expected to
168 // contended. 162 // be heavily contended.
169 base::Lock newly_updatable_lock_; 163 mutable base::Lock has_incoming_immediate_work_lock_;
170 std::vector<internal::TaskQueueImpl*> newly_updatable_;
171 164
172 // Set of task queues with avaliable work on the incoming queue. This should 165 // Set of task queues with avaliable work on the incoming queue. This should
Sami 2017/01/18 17:57:04 Is the second sentence still valid? If it's main-t
alex clarke (OOO till 29th) 2017/01/19 08:50:52 Done.
173 // only be accessed from the main thread. 166 // only be accessed from the main thread.
174 std::set<internal::TaskQueueImpl*> updatable_queue_set_; 167 std::set<internal::TaskQueueImpl*> has_incoming_immediate_work_;
175 168
176 Observer* observer_; // NOT OWNED. 169 Observer* observer_; // NOT OWNED.
177 170
178 base::ThreadChecker main_thread_checker_; 171 base::ThreadChecker main_thread_checker_;
179 172
180 DISALLOW_COPY_AND_ASSIGN(TimeDomain); 173 DISALLOW_COPY_AND_ASSIGN(TimeDomain);
181 }; 174 };
182 175
183 } // namespace scheduler 176 } // namespace scheduler
184 } // namespace blink 177 } // namespace blink
185 178
186 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ 179 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698