aboutsummaryrefslogtreecommitdiff
path: root/src/sched/roundrobin.cpp
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-12-25 17:53:05 +0200
committeraqua <aqua@iserlohn-fortress.net>2022-12-25 17:53:05 +0200
commita490cf9fece4c4b900d219740123ec8d81c6abb2 (patch)
tree3e4485d75519b79b0e770cacf5ba8b66acce8231 /src/sched/roundrobin.cpp
parentGenerate docs using doxygen instead of sphinx (diff)
downloadkernel-a490cf9fece4c4b900d219740123ec8d81c6abb2.tar.xz
Add sched/roundrobin tests
Diffstat (limited to 'src/sched/roundrobin.cpp')
-rw-r--r--src/sched/roundrobin.cpp21
1 files changed, 21 insertions, 0 deletions
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;
+}