Skip to content

Commit defebbc

Browse files
Barath Raghavanddiproietto
authored andcommitted
Consolidates redundant code.
1 parent 01f7085 commit defebbc

1 file changed

Lines changed: 19 additions & 36 deletions

File tree

core/scheduler.h

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,23 @@ class Scheduler {
155155
return wakeup_queue_;
156156
}
157157

158+
// Selects the next TrafficClass to run.
159+
LeafTrafficClass<CallableTask> *Next(uint64_t tsc) {
160+
WakeTCs(tsc);
161+
162+
if (!root_ || root_->blocked()) {
163+
// Nothing to schedule anywhere.
164+
return nullptr;
165+
}
166+
167+
TrafficClass *c = root_;
168+
while (c->policy_ != POLICY_LEAF) {
169+
c = c->PickNextChild();
170+
}
171+
172+
return static_cast<LeafTrafficClass<CallableTask> *>(c);
173+
}
174+
158175
protected:
159176
// Starts at the given class and attempts to unblock classes on the path
160177
// towards the root.
@@ -215,7 +232,7 @@ class DefaultScheduler : public Scheduler<CallableTask> {
215232
resource_arr_t usage;
216233

217234
// Schedule.
218-
LeafTrafficClass<CallableTask> *leaf = Next(this->checkpoint_);
235+
LeafTrafficClass<CallableTask> *leaf = Scheduler<CallableTask>::Next(this->checkpoint_);
219236

220237
uint64_t now;
221238
if (leaf) {
@@ -251,23 +268,6 @@ class DefaultScheduler : public Scheduler<CallableTask> {
251268

252269
this->checkpoint_ = now;
253270
}
254-
255-
// Selects the next TrafficClass to run.
256-
LeafTrafficClass<CallableTask> *Next(uint64_t tsc) {
257-
this->WakeTCs(tsc);
258-
259-
if (!this->root_ || this->root_->blocked()) {
260-
// Nothing to schedule anywhere.
261-
return nullptr;
262-
}
263-
264-
TrafficClass *c = this->root_;
265-
while (c->policy_ != POLICY_LEAF) {
266-
c = c->PickNextChild();
267-
}
268-
269-
return static_cast<LeafTrafficClass<CallableTask> *>(c);
270-
}
271271
};
272272

273273
template <typename CallableTask>
@@ -309,7 +309,7 @@ class ExperimentalScheduler : public Scheduler<CallableTask> {
309309
resource_arr_t usage;
310310

311311
// Schedule.
312-
LeafTrafficClass<CallableTask> *leaf = Next(this->checkpoint_);
312+
LeafTrafficClass<CallableTask> *leaf = Scheduler<CallableTask>::Next(this->checkpoint_);
313313

314314
uint64_t now;
315315
if (leaf) {
@@ -356,23 +356,6 @@ class ExperimentalScheduler : public Scheduler<CallableTask> {
356356

357357
this->checkpoint_ = now;
358358
}
359-
360-
// Selects the next TrafficClass to run.
361-
LeafTrafficClass<CallableTask> *Next(uint64_t tsc) {
362-
this->WakeTCs(tsc);
363-
364-
if (!this->root_ || this->root_->blocked()) {
365-
// Nothing to schedule anywhere.
366-
return nullptr;
367-
}
368-
369-
TrafficClass *c = this->root_;
370-
while (c->policy_ != POLICY_LEAF) {
371-
c = c->PickNextChild();
372-
}
373-
374-
return static_cast<LeafTrafficClass<CallableTask> *>(c);
375-
}
376359
};
377360

378361
} // namespace bess

0 commit comments

Comments
 (0)