Skip to content

Commit d4f4d04

Browse files
author
Tarek
committed
Change ran out time
1 parent c45b31c commit d4f4d04

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

StudentOS/OS.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ void swapOut(int &, int[]);
2525
void swapFromLTS(int &, int[]);
2626

2727

28-
/*LTS is sorted so when you try to swap in a job for IO and you get -1 because memory is full
29-
you sort jobs in ascending order then you swap the biggest one out and delete it from memory. When that's done,
30-
run IO gets called and you swap the job at the top and BAM!
31-
*/
32-
33-
3428
void startup()
3529
{
3630
ontrace();
@@ -97,7 +91,7 @@ void Tro(int &a, int p[])
9791
{
9892
// Timer-Run-Out.
9993
// At call: p [5] = current time
100-
memory.getNextJob()->addCPUTime(p[4]);
94+
memory.getNextJob()->addCPUTime(p[5] - memory.getNextJob()->getPrevClock());
10195
if (memory.getNextJob()->getCPUTime() >= memory.getNextJob()->getMaxCPUTime()) {
10296
cout << "ran out of time" << endl;
10397
if (memory.getNextJob()->isDoingIO() || memory.getNextJob()->getPendingIO() > 0) {
@@ -180,6 +174,7 @@ void runCurrentJob(int &a, int p[]) {
180174
p[3] = memory.getNextJob()->getJobSize();
181175
p[4] = 1;
182176
a = 2;
177+
memory.getNextJob()->setPrevClock(p[5]);
183178
}
184179
else
185180
runFromLTS(a, p);

StudentOS/PCB.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ PCB::PCB(int jobN, int pri, int jobS, int maxTime, int memPos) : jobNumber(jobN)
1111
pendingIO = 0;
1212
inMemory = false;
1313
tooBig = false;
14+
prevClock = 0;
1415
}
1516
PCB::PCB() {
1617
jobNumber = priority = jobSize = maxCPUTime = memoryPos = -1;
@@ -20,6 +21,7 @@ PCB::PCB() {
2021
pendingIO = 0;
2122
inMemory = false;
2223
tooBig = false;
24+
prevClock = 0;
2325
}
2426

2527
PCB::~PCB() {
@@ -108,3 +110,11 @@ void PCB::setTooBig(bool status) {
108110
tooBig = status;
109111
}
110112

113+
void PCB::setPrevClock(int n) {
114+
prevClock = n;
115+
}
116+
117+
int PCB::getPrevClock() {
118+
return prevClock;
119+
}
120+

StudentOS/PCB.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PCB
1616
bool killAfterIO;
1717
bool inMemory;
1818
bool tooBig;
19-
19+
int prevClock;
2020
public:
2121
PCB(int , int , int , int , int);
2222
PCB();
@@ -41,6 +41,8 @@ class PCB
4141
void setInMemory(bool);
4242
bool isTooBig();
4343
void setTooBig(bool);
44+
int getPrevClock();
45+
void setPrevClock(int);
4446
};
4547

4648
#endif

0 commit comments

Comments
 (0)