aboutsummaryrefslogtreecommitdiff
path: root/kernel/sched/roundrobin.cpp
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2024-03-08 17:24:49 +0200
committeraqua <aqua@iserlohn-fortress.net>2024-03-08 22:00:07 +0200
commit20b97ea7c0dbbdc13800e12ff5c86c00c4a342ec (patch)
tree473281e5fc8b256827ce1a678573444e1aa5f669 /kernel/sched/roundrobin.cpp
parentGenerate src/conf.h (diff)
downloadkernel-20b97ea7c0dbbdc13800e12ff5c86c00c4a342ec.tar.xz
Bazel build
Diffstat (limited to 'kernel/sched/roundrobin.cpp')
-rw-r--r--kernel/sched/roundrobin.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/kernel/sched/roundrobin.cpp b/kernel/sched/roundrobin.cpp
new file mode 100644
index 0000000..c3d6cb6
--- /dev/null
+++ b/kernel/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;
+}