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

Side by Side Diff: cc/test/ordered_simple_task_runner.cc

Issue 2546423002: [Try # 3] Scheduler refactoring to virtually eliminate redundant DoWorks (Closed)
Patch Set: Rebased Created 3 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
« no previous file with comments | « cc/test/ordered_simple_task_runner.h ('k') | third_party/WebKit/Source/platform/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "cc/test/ordered_simple_task_runner.h" 5 #include "cc/test/ordered_simple_task_runner.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 130
131 size_t OrderedSimpleTaskRunner::NumPendingTasks() const { 131 size_t OrderedSimpleTaskRunner::NumPendingTasks() const {
132 return pending_tasks_.size(); 132 return pending_tasks_.size();
133 } 133 }
134 134
135 bool OrderedSimpleTaskRunner::HasPendingTasks() const { 135 bool OrderedSimpleTaskRunner::HasPendingTasks() const {
136 return pending_tasks_.size() > 0; 136 return pending_tasks_.size() > 0;
137 } 137 }
138 138
139 base::TimeTicks OrderedSimpleTaskRunner::NextTaskTime() { 139 base::TimeTicks OrderedSimpleTaskRunner::NextTaskTime() {
140 RemoveCancelledTasks();
141
140 if (pending_tasks_.size() <= 0) { 142 if (pending_tasks_.size() <= 0) {
141 return AbsoluteMaxNow(); 143 return AbsoluteMaxNow();
142 } 144 }
143 145
144 return pending_tasks_.begin()->GetTimeToRun(); 146 return pending_tasks_.begin()->GetTimeToRun();
145 } 147 }
146 148
147 base::TimeDelta OrderedSimpleTaskRunner::DelayToNextTaskTime() { 149 base::TimeDelta OrderedSimpleTaskRunner::DelayToNextTaskTime() {
148 DCHECK(thread_checker_.CalledOnValidThread()); 150 DCHECK(thread_checker_.CalledOnValidThread());
151 RemoveCancelledTasks();
149 152
150 if (pending_tasks_.size() <= 0) { 153 if (pending_tasks_.size() <= 0) {
151 return AbsoluteMaxNow() - base::TimeTicks(); 154 return AbsoluteMaxNow() - base::TimeTicks();
152 } 155 }
153 156
154 base::TimeDelta delay = NextTaskTime() - now_src_->NowTicks(); 157 base::TimeDelta delay = NextTaskTime() - now_src_->NowTicks();
155 if (delay > base::TimeDelta()) 158 if (delay > base::TimeDelta())
156 return delay; 159 return delay;
157 return base::TimeDelta(); 160 return base::TimeDelta();
158 } 161 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 modifiable_conditions.push_back(TaskRunCountBelow(max_tasks_)); 194 modifiable_conditions.push_back(TaskRunCountBelow(max_tasks_));
192 195
193 // If to advance now or not 196 // If to advance now or not
194 if (!advance_now_) { 197 if (!advance_now_) {
195 modifiable_conditions.push_back(NowBefore(now_src_->NowTicks())); 198 modifiable_conditions.push_back(NowBefore(now_src_->NowTicks()));
196 } else { 199 } else {
197 modifiable_conditions.push_back(AdvanceNow()); 200 modifiable_conditions.push_back(AdvanceNow());
198 } 201 }
199 202
200 while (pending_tasks_.size() > 0) { 203 while (pending_tasks_.size() > 0) {
204 // Skip canceled tasks.
205 if (pending_tasks_.begin()->task.IsCancelled()) {
206 pending_tasks_.erase(pending_tasks_.begin());
207 continue;
208 }
201 // Check if we should continue to run pending tasks. 209 // Check if we should continue to run pending tasks.
202 bool condition_success = true; 210 bool condition_success = true;
203 for (std::vector<base::Callback<bool(void)>>::iterator it = 211 for (std::vector<base::Callback<bool(void)>>::iterator it =
204 modifiable_conditions.begin(); 212 modifiable_conditions.begin();
205 it != modifiable_conditions.end(); 213 it != modifiable_conditions.end();
206 it++) { 214 it++) {
207 condition_success = it->Run(); 215 condition_success = it->Run();
208 if (!condition_success) 216 if (!condition_success)
209 break; 217 break;
210 } 218 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 } 345 }
338 346
339 bool OrderedSimpleTaskRunner::AdvanceNowCallback() { 347 bool OrderedSimpleTaskRunner::AdvanceNowCallback() {
340 base::TimeTicks next_task_time = NextTaskTime(); 348 base::TimeTicks next_task_time = NextTaskTime();
341 if (now_src_->NowTicks() < next_task_time) { 349 if (now_src_->NowTicks() < next_task_time) {
342 now_src_->Advance(next_task_time - now_src_->NowTicks()); 350 now_src_->Advance(next_task_time - now_src_->NowTicks());
343 } 351 }
344 return true; 352 return true;
345 } 353 }
346 354
355 void OrderedSimpleTaskRunner::RemoveCancelledTasks() {
356 std::set<TestOrderablePendingTask>::iterator it = pending_tasks_.begin();
357 while (it != pending_tasks_.end()) {
358 if (it->task.IsCancelled()) {
359 it = pending_tasks_.erase(it);
360 } else {
361 it++;
362 }
363 }
364 }
365
347 } // namespace cc 366 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/ordered_simple_task_runner.h ('k') | third_party/WebKit/Source/platform/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698