new idea
This commit is contained in:
@@ -5,17 +5,26 @@ void Scheduler::EnqueueRelative(const u64 t, const EventType type) { EnqueueAbso
|
|||||||
|
|
||||||
void Scheduler::EnqueueAbsolute(const u64 t, const EventType type) { events.push({t, type}); }
|
void Scheduler::EnqueueAbsolute(const u64 t, const EventType type) { events.push({t, type}); }
|
||||||
|
|
||||||
u64 Scheduler::Remove(const EventType eventType) const {
|
Event *Scheduler::Find(const EventType eventType) const {
|
||||||
for (auto &[time, type] : events) {
|
for (auto &event : events) {
|
||||||
if (type == eventType) {
|
if (event.type == eventType) {
|
||||||
const u64 ret = time - ticks;
|
const u64 ret = event.time - ticks;
|
||||||
type = NONE;
|
return &event;
|
||||||
time = ticks;
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 Scheduler::Remove(const EventType eventType) const {
|
||||||
|
auto event = Find(eventType);
|
||||||
|
if (!event)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
const u64 ret = event->time - ticks;
|
||||||
|
event->type = NONE;
|
||||||
|
event->time = ticks;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scheduler::Tick(const u64 t) {
|
void Scheduler::Tick(const u64 t) {
|
||||||
@@ -40,10 +49,14 @@ void Scheduler::Tick(const u64 t) {
|
|||||||
case NONE:
|
case NONE:
|
||||||
break;
|
break;
|
||||||
case IMPOSSIBLE:
|
case IMPOSSIBLE:
|
||||||
Util::Error::GetInstance().Throw({Util::Error::Severity::UNRECOVERABLE}, {Util::Error::Type::ROM_LOAD_ERROR}, {}, {}, "Unrecognized rom endianness");
|
Util::Error::GetInstance().Throw({Util::Error::Severity::UNRECOVERABLE},
|
||||||
|
{Util::Error::Type::ROM_LOAD_ERROR}, {}, {},
|
||||||
|
"Unrecognized rom endianness");
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
Util::Error::GetInstance().Throw({Util::Error::Severity::UNRECOVERABLE}, {Util::Error::Type::ROM_LOAD_ERROR}, {}, {}, "Unknown scheduler event type {}", static_cast<int>(type));
|
Util::Error::GetInstance().Throw({Util::Error::Severity::UNRECOVERABLE},
|
||||||
|
{Util::Error::Type::ROM_LOAD_ERROR}, {}, {},
|
||||||
|
"Unknown scheduler event type {}", static_cast<int>(type));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
events.pop();
|
events.pop();
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ struct Scheduler {
|
|||||||
void EnqueueRelative(u64, EventType);
|
void EnqueueRelative(u64, EventType);
|
||||||
void EnqueueAbsolute(u64, EventType);
|
void EnqueueAbsolute(u64, EventType);
|
||||||
[[nodiscard]] u64 Remove(EventType) const;
|
[[nodiscard]] u64 Remove(EventType) const;
|
||||||
|
[[nodiscard]] Event *Find(EventType) const;
|
||||||
void Tick(u64 t);
|
void Tick(u64 t);
|
||||||
|
|
||||||
u8 index = 0;
|
u8 index = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user