Added class Schedule for threads
This commit is contained in:
27
luprex/core/cpp/sched.cpp
Normal file
27
luprex/core/cpp/sched.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
#include "sched.hpp"
|
||||
|
||||
bool SchedEntry::operator < (const SchedEntry &other) const {
|
||||
if (clock_ < other.clock_) return true;
|
||||
if (clock_ > other.clock_) return false;
|
||||
if (thread_id_ < other.thread_id_) return true;
|
||||
if (thread_id_ > other.thread_id_) return false;
|
||||
if (place_id_ < other.place_id_) return true;
|
||||
if (place_id_ > other.place_id_) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Schedule::add(int64_t clk, int64_t thid, int64_t plid) {
|
||||
schedule_.insert(SchedEntry(clk, thid, plid));
|
||||
}
|
||||
|
||||
bool Schedule::ready(int64_t clk) const {
|
||||
return (!schedule_.empty()) && (schedule_.begin()->clock() <= clk);
|
||||
}
|
||||
|
||||
SchedEntry Schedule::pop() {
|
||||
SchedEntry result = *schedule_.begin();
|
||||
schedule_.erase(schedule_.begin());
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user