From a490cf9fece4c4b900d219740123ec8d81c6abb2 Mon Sep 17 00:00:00 2001 From: aqua Date: Sun, 25 Dec 2022 17:53:05 +0200 Subject: Add sched/roundrobin tests --- src/sched/roundrobin.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/sched/roundrobin.cpp (limited to 'src/sched/roundrobin.cpp') diff --git a/src/sched/roundrobin.cpp b/src/sched/roundrobin.cpp new file mode 100644 index 0000000..c3d6cb6 --- /dev/null +++ b/src/sched/roundrobin.cpp @@ -0,0 +1,21 @@ +#include "../sched.hpp" + +/// Each task is run for a time quantum or the remainder of its cpu burst +Task * +RoundRobinQueue::next(int slice) +{ + if (head == nullptr) return nullptr; + if (head->node->burst <= 0) { + delete head->node; + remove(head->node); + return next(slice); + } + + auto *it = head; + it->node->burst -= slice; + if (head->next) head = head->next; + it->next = nullptr; + tail->next = it; + tail = it; + return it->node; +} -- cgit v1.2.1