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

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

Issue 2546423002: [Try # 3] Scheduler refactoring to virtually eliminate redundant DoWorks (Closed)
Patch Set: Rebased Created 4 years 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 // Returns a LazyNow that evaluate this TimeDomain's Now. Can be called from 57 // Returns a LazyNow that evaluate this TimeDomain's Now. Can be called from
58 // any thread. 58 // any thread.
59 // TODO(alexclarke): Make this main thread only. 59 // TODO(alexclarke): Make this main thread only.
60 virtual LazyNow CreateLazyNow() const = 0; 60 virtual LazyNow CreateLazyNow() const = 0;
61 61
62 // Evaluate this TimeDomain's Now. Can be called from any thread. 62 // Evaluate this TimeDomain's Now. Can be called from any thread.
63 virtual base::TimeTicks Now() const = 0; 63 virtual base::TimeTicks Now() const = 0;
64 64
65 // Some TimeDomains support virtual time, this method tells us to advance time 65 // Some TimeDomains support virtual time, this method tells us to advance time
66 // if possible and return true if time was advanced. 66 // if possible and return true if time was advanced.
Sami 2016/12/07 16:13:43 nit: Comment needs updating.
alex clarke (OOO till 29th) 2016/12/08 17:38:49 Done.
67 virtual bool MaybeAdvanceTime() = 0; 67 virtual base::Optional<base::TimeDelta> DelayTillNextTask(
68 LazyNow* lazy_now) = 0;
68 69
69 // Returns the name of this time domain for tracing. 70 // Returns the name of this time domain for tracing.
70 virtual const char* GetName() const = 0; 71 virtual const char* GetName() const = 0;
71 72
72 // If there is a scheduled delayed task, |out_time| is set to the scheduled 73 // If there is a scheduled delayed task, |out_time| is set to the scheduled
73 // runtime for the next one and it returns true. Returns false otherwise. 74 // runtime for the next one and it returns true. Returns false otherwise.
74 bool NextScheduledRunTime(base::TimeTicks* out_time) const; 75 bool NextScheduledRunTime(base::TimeTicks* out_time) const;
75 76
76 protected: 77 protected:
77 friend class internal::TaskQueueImpl; 78 friend class internal::TaskQueueImpl;
78 friend class TaskQueueManager; 79 friend class TaskQueueManager;
79 80
80 void AsValueInto(base::trace_event::TracedValue* state) const; 81 void AsValueInto(base::trace_event::TracedValue* state) const;
81 82
82 // Migrates |queue| from this time domain to |destination_time_domain|. 83 // Migrates |queue| from this time domain to |destination_time_domain|.
83 // Main-thread only. 84 // Main-thread only.
84 void MigrateQueue(internal::TaskQueueImpl* queue, 85 void MigrateQueue(internal::TaskQueueImpl* queue,
85 TimeDomain* destination_time_domain); 86 TimeDomain* destination_time_domain);
86 87
87 // If there is a scheduled delayed task, |out_task_queue| is set to the queue 88 // 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. 89 // the next task was posted to and it returns true. Returns false otherwise.
89 bool NextScheduledTaskQueue(TaskQueue** out_task_queue) const; 90 bool NextScheduledTaskQueue(TaskQueue** out_task_queue) const;
90 91
91 // Adds |queue| to the set of task queues that UpdateWorkQueues calls
92 // UpdateWorkQueue on.
93 void RegisterAsUpdatableTaskQueue(internal::TaskQueueImpl* queue);
94
95 // Schedules a call to TaskQueueImpl::WakeUpForDelayedWork when this 92 // Schedules a call to TaskQueueImpl::WakeUpForDelayedWork when this
96 // TimeDomain reaches |delayed_run_time|. This supersedes any previously 93 // TimeDomain reaches |delayed_run_time|. This supersedes any previously
97 // registered wakeup for |queue|. 94 // registered wakeup for |queue|.
98 void ScheduleDelayedWork(internal::TaskQueueImpl* queue, 95 void ScheduleDelayedWork(internal::TaskQueueImpl* queue,
99 base::TimeTicks delayed_run_time, 96 base::TimeTicks delayed_run_time,
100 base::TimeTicks now); 97 base::TimeTicks now);
101 98
102 // Registers the |queue|. 99 // Registers the |queue|.
103 void RegisterQueue(internal::TaskQueueImpl* queue); 100 void RegisterQueue(internal::TaskQueueImpl* queue);
104 101
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. 102 // Removes |queue| from all internal data structures.
110 void UnregisterQueue(internal::TaskQueueImpl* queue); 103 void UnregisterQueue(internal::TaskQueueImpl* queue);
111 104
112 // Updates active queues associated with this TimeDomain. 105 // Tells the time domain that |queue| went from having no immediate work to
113 void UpdateWorkQueues(LazyNow lazy_now); 106 // having some.
107 void OnQueueHasImmediateWork(internal::TaskQueueImpl* queue);
114 108
115 // Called by the TaskQueueManager when the TimeDomain is registered. 109 // Called by the TaskQueueManager when the TimeDomain is registered.
116 virtual void OnRegisterWithTaskQueueManager( 110 virtual void OnRegisterWithTaskQueueManager(
117 TaskQueueManager* task_queue_manager) = 0; 111 TaskQueueManager* task_queue_manager) = 0;
118 112
119 // The implementaion will secedule task processing to run with |delay| with 113 // The implementaion will secedule task processing to run with |delay| with
120 // respect to the TimeDomain's time source. Always called on the main thread. 114 // respect to the TimeDomain's time source. Always called on the main thread.
121 // NOTE this is only called by ScheduleDelayedWork if the scheduled runtime 115 // NOTE this is only called by ScheduleDelayedWork if the scheduled runtime
122 // is sooner than any previously sheduled work or if there is no other 116 // is sooner than any previously sheduled work or if there is no other
123 // scheduled work. 117 // scheduled work.
124 virtual void RequestWakeup(base::TimeTicks now, base::TimeDelta delay) = 0; 118 virtual void RequestWakeup(base::TimeTicks now, base::TimeDelta delay) = 0;
125 119
126 // For implementation specific tracing. 120 // For implementation specific tracing.
127 virtual void AsValueIntoInternal( 121 virtual void AsValueIntoInternal(
128 base::trace_event::TracedValue* state) const = 0; 122 base::trace_event::TracedValue* state) const = 0;
129 123
130 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay 124 // Call TaskQueueImpl::UpdateDelayedWorkQueue for each queue where the delay
131 // has elapsed. 125 // has elapsed.
132 void WakeupReadyDelayedQueues(LazyNow* lazy_now); 126 void WakeupReadyDelayedQueues(LazyNow* lazy_now);
133 127
134 size_t NumberOfScheduledWakeups() const { 128 size_t NumberOfScheduledWakeups() const {
135 return delayed_wakeup_queue_.size(); 129 return delayed_wakeup_queue_.size();
136 } 130 }
137 131
138 private: 132 private:
139 void MoveNewlyUpdatableQueuesIntoUpdatableQueueSet();
140
141 struct DelayedWakeup { 133 struct DelayedWakeup {
142 base::TimeTicks time; 134 base::TimeTicks time;
143 internal::TaskQueueImpl* queue; 135 internal::TaskQueueImpl* queue;
144 136
145 bool operator<=(const DelayedWakeup& other) const { 137 bool operator<=(const DelayedWakeup& other) const {
146 if (time == other.time) 138 if (time == other.time)
147 return queue <= other.queue; 139 return queue <= other.queue;
148 return time < other.time; 140 return time < other.time;
149 } 141 }
150 142
151 void SetHeapHandle(HeapHandle handle) { 143 void SetHeapHandle(HeapHandle handle) {
152 DCHECK(handle.IsValid()); 144 DCHECK(handle.IsValid());
153 queue->set_heap_handle(handle); 145 queue->set_heap_handle(handle);
154 } 146 }
155 147
156 void ClearHeapHandle() { 148 void ClearHeapHandle() {
157 DCHECK(queue->heap_handle().IsValid()); 149 DCHECK(queue->heap_handle().IsValid());
158 queue->set_heap_handle(HeapHandle()); 150 queue->set_heap_handle(HeapHandle());
159 151
160 DCHECK_NE(queue->scheduled_time_domain_wakeup(), base::TimeTicks()); 152 DCHECK_NE(queue->scheduled_time_domain_wakeup(), base::TimeTicks());
161 queue->set_scheduled_time_domain_wakeup(base::TimeTicks()); 153 queue->set_scheduled_time_domain_wakeup(base::TimeTicks());
162 } 154 }
163 }; 155 };
164 156
165 IntrusiveHeap<DelayedWakeup> delayed_wakeup_queue_; 157 IntrusiveHeap<DelayedWakeup> delayed_wakeup_queue_;
166 158
167 // This lock guards only |newly_updatable_|. It's not expected to be heavily
168 // contended.
169 base::Lock newly_updatable_lock_;
170 std::vector<internal::TaskQueueImpl*> newly_updatable_;
171
172 // Set of task queues with avaliable work on the incoming queue. This should
173 // only be accessed from the main thread.
174 std::set<internal::TaskQueueImpl*> updatable_queue_set_;
175
176 Observer* observer_; // NOT OWNED. 159 Observer* observer_; // NOT OWNED.
177 160
178 base::ThreadChecker main_thread_checker_; 161 base::ThreadChecker main_thread_checker_;
179 162
180 DISALLOW_COPY_AND_ASSIGN(TimeDomain); 163 DISALLOW_COPY_AND_ASSIGN(TimeDomain);
181 }; 164 };
182 165
183 } // namespace scheduler 166 } // namespace scheduler
184 } // namespace blink 167 } // namespace blink
185 168
186 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_ 169 #endif // THIRD_PARTY_WEBKIT_SOURCE_PLATFORM_SCHEDULER_BASE_TIME_DOMAIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698