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

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

Issue 2546423002: [Try # 3] Scheduler refactoring to virtually eliminate redundant DoWorks (Closed)
Patch Set: Added the MoveableAutoLock per Sami's suggestion 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 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 CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ 5 #ifndef CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_
6 #define CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ 6 #define CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // prevent infinite task loops. 70 // prevent infinite task loops.
71 static const size_t kAbsoluteMaxTasks; 71 static const size_t kAbsoluteMaxTasks;
72 void SetRunTaskLimit(size_t max_tasks) { max_tasks_ = max_tasks; } 72 void SetRunTaskLimit(size_t max_tasks) { max_tasks_ = max_tasks; }
73 void ClearRunTaskLimit() { max_tasks_ = kAbsoluteMaxTasks; } 73 void ClearRunTaskLimit() { max_tasks_ = kAbsoluteMaxTasks; }
74 74
75 // Allow task runner to advance now when running tasks. 75 // Allow task runner to advance now when running tasks.
76 void SetAutoAdvanceNowToPendingTasks(bool advance_now) { 76 void SetAutoAdvanceNowToPendingTasks(bool advance_now) {
77 advance_now_ = advance_now; 77 advance_now_ = advance_now;
78 } 78 }
79 79
80 size_t NumPendingTasks() const; 80 size_t NumPendingTasks();
81 bool HasPendingTasks() const; 81 bool HasPendingTasks();
82 base::TimeTicks NextTaskTime(); 82 base::TimeTicks NextTaskTime();
83 base::TimeDelta DelayToNextTaskTime(); 83 base::TimeDelta DelayToNextTaskTime();
84 84
85 // Run tasks while the callback returns true or too many tasks have been run. 85 // Run tasks while the callback returns true or too many tasks have been run.
86 // Returns true if there are still pending tasks left. 86 // Returns true if there are still pending tasks left.
87 bool RunTasksWhile(base::Callback<bool(void)> condition); 87 bool RunTasksWhile(base::Callback<bool(void)> condition);
88 88
89 // Run tasks while *all* of the callbacks return true or too many tasks have 89 // Run tasks while *all* of the callbacks return true or too many tasks have
90 // been run. Exits on the *first* condition which returns false, skipping 90 // been run. Exits on the *first* condition which returns false, skipping
91 // calling all remaining conditions. Conditions can have side effects, 91 // calling all remaining conditions. Conditions can have side effects,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 // Advance Now() to the next task to run. 130 // Advance Now() to the next task to run.
131 base::Callback<bool(void)> AdvanceNow(); 131 base::Callback<bool(void)> AdvanceNow();
132 132
133 protected: 133 protected:
134 static bool TaskRunCountBelowCallback(size_t max_tasks, size_t* task_run); 134 static bool TaskRunCountBelowCallback(size_t max_tasks, size_t* task_run);
135 bool TaskExistedInitiallyCallback( 135 bool TaskExistedInitiallyCallback(
136 const std::set<TestOrderablePendingTask>& existing_tasks); 136 const std::set<TestOrderablePendingTask>& existing_tasks);
137 bool NowBeforeCallback(base::TimeTicks stop_at); 137 bool NowBeforeCallback(base::TimeTicks stop_at);
138 bool AdvanceNowCallback(); 138 bool AdvanceNowCallback();
139 void RemovePendingCancelledTasks();
139 140
140 ~OrderedSimpleTaskRunner() override; 141 ~OrderedSimpleTaskRunner() override;
141 142
142 base::ThreadChecker thread_checker_; 143 base::ThreadChecker thread_checker_;
143 144
144 bool advance_now_; 145 bool advance_now_;
145 // Not owned. 146 // Not owned.
146 base::SimpleTestTickClock* now_src_; 147 base::SimpleTestTickClock* now_src_;
147 148
148 size_t max_tasks_; 149 size_t max_tasks_;
149 150
150 bool inside_run_tasks_until_; 151 bool inside_run_tasks_until_;
151 std::set<TestOrderablePendingTask> pending_tasks_; 152 std::set<TestOrderablePendingTask> pending_tasks_;
152 153
153 private: 154 private:
154 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner); 155 DISALLOW_COPY_AND_ASSIGN(OrderedSimpleTaskRunner);
155 }; 156 };
156 157
157 } // namespace cc 158 } // namespace cc
158 159
159 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_ 160 #endif // CC_TEST_ORDERED_SIMPLE_TASK_RUNNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698