-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcess.cpp
More file actions
60 lines (51 loc) · 1.39 KB
/
Process.cpp
File metadata and controls
60 lines (51 loc) · 1.39 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
#include "Process.h"
#include <algorithm>
// Default Constructor
Process::Process() {
arrival = -1;
burst = -1;
burstLeft = -1;
completionTime = -1;
deadline = -1;
priority = -1;
ioTime = -1;
ioTimeLeft = -1;
}
Process::Process(int pid, int arrival, int burst, int deadline, int priority, int ioTime) {
this->pid = pid;
this->arrival = arrival;
this->burst = burst;
this->burstLeft = burst;
this->deadline = deadline;
this->priority = priority;
this->ioTime = ioTime;
this->ioTimeLeft = ioTime;
this->completionTime = -1;
this->endClockTick = -1;
this->queueIndex = 0;
this->quantumLeft = -1;
this->ioOffsetLeft = -1;
}
int Process::getTurnaroundTime() {
if (completionTime == -1) {
return -1;
}
return completionTime - arrival;
}
int Process::getWaitTime(bool hasIO) {
if (completionTime == -1) {
return -1;
}
if(hasIO) {
return completionTime - arrival - burst - ioTime;
}
return completionTime - arrival - burst;
}
void Process::setEndClockTick(int currentClockTick, int ioOffset) {
if(ioTimeLeft <= 0) {
endClockTick = currentClockTick + std::min(burstLeft, quantumLeft);
} else {
int offsetLeft = ioOffset - (burst - burstLeft);
endClockTick = currentClockTick + std::min(std::min(burstLeft, quantumLeft), offsetLeft);
}
}