-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTScheduler.h
More file actions
68 lines (55 loc) · 1.78 KB
/
RTScheduler.h
File metadata and controls
68 lines (55 loc) · 1.78 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "Average.h"
#include <vector>
#include <queue>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include "Process.h"
#ifndef SCHED_RTSCHEDULER_H
#define SCHED_RTSCHEDULER_H
using std::vector;
using std::stringstream;
using std::priority_queue;
class RTComparator {
public:
bool operator()(Process *lh, Process *rh) {
if (lh->getDeadline() != rh->getDeadline()) {
return lh->getDeadline() > rh->getDeadline(); // want lower getDeadline()s first
} else {
// If arrival is the same put higher priority process first. Lower priority value means higher priority
return lh->getPriority() > rh->getPriority();
}
}
};
class MinSlackComparator {
public:
bool operator()(Process *lh, Process *rh) {
if (lh->getSlackTime() != rh->getSlackTime()) {
return lh->getSlackTime() > rh->getSlackTime(); // want lower slacktime first
} else {
return lh->getArrival() > rh->getArrival();
}
}
};
class RTScheduler {
private:
int clock;
Average average;
vector<Process> processes;
vector<Process>::iterator processIterator;
bool finished;
bool hard;
bool failed;
int failureTime;
stringstream buffer;
priority_queue<Process*, vector<Process*>, RTComparator> queue;
priority_queue<Process*, vector<Process*>, MinSlackComparator> topProcesses;
bool addArrivedProcesses(int clockTime);
void addToTopProcesses(int deadline);
void setFailureTime(int time) { failureTime = std::min(failureTime, time);}
Process *getTopOfQueue();
public:
RTScheduler(vector<Process>& allProcesses, bool hard, int clockStart);
void run();
};
#endif //SCHED_RTSCHEDULER_H