aboutsummaryrefslogtreecommitdiff
path: root/src/sched/roundrobin.cpp
blob: c3d6cb6b64cb462601a3c7005b1c1db4d31730ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
}