Files
integration/luprex/core/cpp/sched.cpp

47 lines
1.3 KiB
C++

#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;
}
void Schedule::serialize(StreamBuffer *sb) {
sb->write_uint32(schedule_.size());
for (const SchedEntry &entry : schedule_) {
sb->write_int64(entry.clock_);
sb->write_int64(entry.thread_id_);
sb->write_int64(entry.place_id_);
}
}
void Schedule::deserialize(StreamBuffer *sb) {
schedule_.clear();
size_t nentry = sb->read_uint32();
for (size_t i = 0; i < nentry; i++) {
int64_t clock = sb->read_int64();
int64_t thread_id = sb->read_int64();
int64_t place_id = sb->read_int64();
add(clock, thread_id, place_id);
}
}