-
Notifications
You must be signed in to change notification settings - Fork 0
/
EDFScheduler.cpp
executable file
·49 lines (41 loc) · 1.31 KB
/
EDFScheduler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* EDFScheduler.cpp
*
* Concrete subclass of a Scheduler implementing the
* Earliest Deadline First scheduling algorithm.
*
* Created on: Mar 13, 2013
* Author: dam7633
*/
#include "EDFScheduler.h"
EDFScheduler::EDFScheduler() {
}
EDFScheduler::~EDFScheduler() {
}
void EDFScheduler::scheduleTasks() {
// Initialize variables for determining the earliest deadline task.
int earliestIdx = -1;
long earliestDeadline = LONG_MAX;
long currentEarliestDeadline;
// Iterate over all the tasks
for (std::size_t i = 0; i < taskSet.size(); i++) {
Task *task = taskSet[i];
//if this task is running, set it back to ready
if(task->getPriority() != TP_READY) {
task->setPriority(TP_READY);
}
//look at the deadlines of those tasks which are ready or running
if(task->getState() == TP_READY || task->getState() == TP_RUNNING) {
//The time-to-deadline is equal to the deadline - the time elapsed since the last deadline
currentEarliestDeadline = task->getRemainingDeadline();
if(currentEarliestDeadline < earliestDeadline) {
earliestIdx = i;
earliestDeadline = currentEarliestDeadline;
}
}
}
//With the earliest deadline known, set that task to running...
if(earliestIdx != -1) {
taskSet[earliestIdx]->setPriority(TP_RUNNING);
}
}