Skip to content

Commit

Permalink
Consolidates redundant code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Barath Raghavan authored and ddiproietto committed May 20, 2017
1 parent 01f7085 commit defebbc
Showing 1 changed file with 19 additions and 36 deletions.
55 changes: 19 additions & 36 deletions core/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ class Scheduler {
return wakeup_queue_;
}

// Selects the next TrafficClass to run.
LeafTrafficClass<CallableTask> *Next(uint64_t tsc) {
WakeTCs(tsc);

if (!root_ || root_->blocked()) {
// Nothing to schedule anywhere.
return nullptr;
}

TrafficClass *c = root_;
while (c->policy_ != POLICY_LEAF) {
c = c->PickNextChild();
}

return static_cast<LeafTrafficClass<CallableTask> *>(c);
}

protected:
// Starts at the given class and attempts to unblock classes on the path
// towards the root.
Expand Down Expand Up @@ -215,7 +232,7 @@ class DefaultScheduler : public Scheduler<CallableTask> {
resource_arr_t usage;

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

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

this->checkpoint_ = now;
}

// Selects the next TrafficClass to run.
LeafTrafficClass<CallableTask> *Next(uint64_t tsc) {
this->WakeTCs(tsc);

if (!this->root_ || this->root_->blocked()) {
// Nothing to schedule anywhere.
return nullptr;
}

TrafficClass *c = this->root_;
while (c->policy_ != POLICY_LEAF) {
c = c->PickNextChild();
}

return static_cast<LeafTrafficClass<CallableTask> *>(c);
}
};

template <typename CallableTask>
Expand Down Expand Up @@ -309,7 +309,7 @@ class ExperimentalScheduler : public Scheduler<CallableTask> {
resource_arr_t usage;

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

uint64_t now;
if (leaf) {
Expand Down Expand Up @@ -356,23 +356,6 @@ class ExperimentalScheduler : public Scheduler<CallableTask> {

this->checkpoint_ = now;
}

// Selects the next TrafficClass to run.
LeafTrafficClass<CallableTask> *Next(uint64_t tsc) {
this->WakeTCs(tsc);

if (!this->root_ || this->root_->blocked()) {
// Nothing to schedule anywhere.
return nullptr;
}

TrafficClass *c = this->root_;
while (c->policy_ != POLICY_LEAF) {
c = c->PickNextChild();
}

return static_cast<LeafTrafficClass<CallableTask> *>(c);
}
};

} // namespace bess
Expand Down

0 comments on commit defebbc

Please sign in to comment.