Skip to content

Commit 25cc230

Browse files
author
Tarek
committed
Clean code
1 parent 3f33a55 commit 25cc230

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

StudentOS/Memory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55

66
/*
7-
can decrease response time to 1749 if I sort IO maxcputime but dilation would be 1.55
8-
sort IO by maxcputime dilation = 1.30, response = 2.3, jobs = 441
7+
can decrease response time to 1749 if I sort IO maxcputime but dilation would be 1.55 with LTS by remainingtime
8+
sort IO by maxcputime dilation = 1.30, response = 2.3, jobs = 441 with LTS by size
99
*/
1010
Memory::Memory()
1111
{

StudentOS/OS.cpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ void siodisk(int jobnum);
1515
void ontrace();
1616
void offtrace();
1717
void runCurrentJob(int &, int []);
18-
void runIO(int &, int[]);
18+
void runIO(int &, int[], bool);
19+
void freeMemory(int &, int[], int);
20+
1921

2022

2123
void startup()
@@ -48,21 +50,20 @@ void Crint(int &a, int p[])
4850

4951
void Dskint(int &a, int p[])
5052
{
51-
cout << "disk interrupt" << " " << a << endl;
53+
cout << "disk interrupt" << endl;
5254
doingIO = false;
5355
if (memory.getJobDoingIO()->shouldKill()) {
5456
cout << "killed it" << endl;
5557
memory.deleteFromMemory(memory.getJobDoingIO());
5658
}
57-
else
59+
else {
60+
memory.getJobDoingIO()->setDoingIO(false);
5861
if (memory.getJobDoingIO()->isBlocked()) {
5962
memory.getJobDoingIO()->setBlocked(false);
60-
memory.getJobDoingIO()->setDoingIO(false);
6163
memory.push(memory.getJobDoingIO());
6264
}
63-
else
64-
memory.getJobDoingIO()->setDoingIO(false);
65-
runIO(a, p);
65+
}
66+
runIO(a, p, false);
6667
runCurrentJob(a, p);
6768
}
6869

@@ -75,7 +76,7 @@ void Drmint(int &a, int p[])
7576
}
7677
else
7778
swapper.setSwappingOut(false);
78-
runIO(a, p);
79+
runIO(a, p, false);
7980
runCurrentJob(a, p);
8081
swapper.swapFromLTS(a, p, memory);
8182
swapper.swapOut(a, p, memory);
@@ -111,14 +112,10 @@ void Svc(int &a, int p[])
111112
}
112113
break;
113114

114-
case 6:
115-
if (a == 6) { //needs IO
116-
memory.getNextJob()->incrementPendingIO();
117-
IO.push_back(memory.getNextJob());
118-
runIO(a, p);
119-
}
115+
case 6: //needs IO
116+
runIO(a, p, true);
120117
break;
121-
118+
122119
case 7: //block
123120
if (memory.getNextJob()->isDoingIO()) {
124121
cout << "Doing IO" << endl;
@@ -148,7 +145,11 @@ void runCurrentJob(int &a, int p[]) {
148145
swapper.runFromLTS(a, p, memory);
149146
}
150147

151-
void runIO(int &a, int p[]) {
148+
void runIO(int &a, int p[], bool newRequest) {
149+
if (newRequest) {
150+
memory.getNextJob()->incrementPendingIO();
151+
IO.push_back(memory.getNextJob());
152+
}
152153
std::sort(IO.begin(), IO.end(), memory.sortIO);
153154
cout << IO.size() << " " << doingIO << endl;
154155
if (!IO.empty() && !doingIO) {
@@ -164,18 +165,23 @@ void runIO(int &a, int p[]) {
164165
if (memoryPos != -1)
165166
swapper.swapIn(a, p, IO.back(), memoryPos);
166167
else {
167-
if (swapper.swapOutQEmpty() && !swapper.isSwappingIn() && !swapper.isSwappingOut()) {
168-
PCB* temp = memory.findLargestJob();
169-
cout << "Swapout #" << temp->getJobNumber() << " " << memoryPos << endl;
170-
swapper.addToSwapOutQ(temp);
171-
swapper.swapOut(a, p, memory);
172-
}
168+
freeMemory(a, p, memoryPos);
173169
}
174170
}
175171
}
176172
}
177173

178174

175+
void freeMemory(int &a, int p[], int memoryPos) {
176+
if (swapper.swapOutQEmpty() && !swapper.isSwappingIn() && !swapper.isSwappingOut()) {
177+
PCB* temp = memory.findLargestJob();
178+
cout << "Swapout #" << temp->getJobNumber() << " " << memoryPos << endl;
179+
swapper.addToSwapOutQ(temp);
180+
swapper.swapOut(a, p, memory);
181+
}
182+
}
183+
184+
179185

180186

181187

0 commit comments

Comments
 (0)