2021-02-18 17:21:25 -05:00
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
}
|
2021-03-16 12:19:37 -04:00
|
|
|
|
|
|
|
|
void Schedule::serialize(StreamBuffer *sb) {
|
2021-07-19 17:32:24 -04:00
|
|
|
sb->write_uint32(schedule_.size());
|
2021-03-16 12:19:37 -04:00
|
|
|
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();
|
2021-07-19 17:32:24 -04:00
|
|
|
size_t nentry = sb->read_uint32();
|
2021-03-16 12:19:37 -04:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|