I hate timers

This commit is contained in:
wheremyfoodat 2023-08-14 17:24:53 +03:00
parent 1354b0f7fa
commit 8881467505
4 changed files with 69 additions and 12 deletions

View file

@ -35,6 +35,7 @@ class Kernel {
std::vector<KernelObject> objects;
std::vector<Handle> portHandles;
std::vector<Handle> mutexHandles;
std::vector<Handle> timerHandles;
// Thread indices, sorted by priority
std::vector<int> threadIndices;
@ -84,6 +85,7 @@ private:
void releaseMutex(Mutex* moo);
void cancelTimer(Timer* timer);
void signalTimer(Handle timerHandle, Timer* timer);
void updateTimer(Handle timerHandle, Timer* timer);
// Wake up the thread with the highest priority out of all threads in the waitlist
// Returns the index of the woken up thread
@ -182,6 +184,14 @@ public:
void requireReschedule() { needReschedule = true; }
void evalReschedule() {
for (auto handle : timerHandles) {
const auto object = getObject(handle, KernelObjectType::Timer);
if (object != nullptr) {
Timer* timer = object->getData<Timer>();
updateTimer(handle, timer);
}
}
if (needReschedule) {
needReschedule = false;
rescheduleThreads();