Skip to content

Commit 867640c

Browse files
author
Tarek
committed
Switch STS to SJN
1 parent d12ec2d commit 867640c

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

StudentOS/Memory.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ bool Memory::sortByAddress(pair<int, int> left, pair<int, int> right) {
1616
return left.first < right.first;
1717
}
1818

19+
bool Memory::sortByMaxCPUTime(PCB* left, PCB* right) {
20+
return left->getMaxCPUTime() > right->getMaxCPUTime();
21+
}
1922

2023
bool Memory::insertNewJob(PCB *newJob) {
2124
if (findSpot(newJob->getJobSize()) != -1) {
@@ -29,7 +32,8 @@ bool Memory::insertNewJob(PCB *newJob) {
2932
else
3033
FST.erase(FST.begin() + i);
3134
newJob->setMemoryPos(oldSpace.first);
32-
jobs.push(newJob);
35+
jobs.push_back(newJob);
36+
std::sort(jobs.begin(), jobs.end(), sortByMaxCPUTime);
3337
}
3438
else
3539
return false;
@@ -88,28 +92,29 @@ void Memory::printFST() {
8892
PCB * Memory::getNextJob() {
8993
if (jobs.empty())
9094
NULL;
91-
return jobs.front();
95+
return jobs.back();
9296
}
9397

9498
bool Memory::isEmpty() {
9599
return jobs.empty();
96100
}
97101

98102
void Memory::pop() {
99-
jobs.pop();
103+
jobs.pop_back();
100104
}
101105

102106
void Memory::push(PCB* p) {
103-
jobs.push(p);
107+
jobs.push_back(p);
108+
std::sort(jobs.begin(), jobs.end(), sortByMaxCPUTime);
104109
}
105110

106111
int Memory::getCount() {
107112
return jobs.size();
108113
}
109114

110115
void Memory::blockJob() {
111-
jobs.front()->setBlocked(true);
112-
jobs.pop();
116+
jobs.back()->setBlocked(true);
117+
jobs.pop_back();
113118
}
114119

115120
void Memory::killAfterIO(PCB* p) {

StudentOS/Memory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Memory
99
private:
1010
vector<pair<int,int> > FST;
1111
int findSpot(int);
12-
queue<PCB*> jobs;
12+
vector<PCB*> jobs;
1313
PCB* jobDoingIO;
1414
public:
1515
Memory();
@@ -18,6 +18,7 @@ class Memory
1818
bool deleteFromMemory(PCB *);
1919
static bool sortBySize(pair<int, int>, pair<int, int>);
2020
static bool sortByAddress(pair<int, int>, pair<int, int>);
21+
static bool sortByMaxCPUTime(PCB*, PCB*);
2122
void printFST();
2223
PCB* getNextJob();
2324
bool isEmpty();

StudentOS/OS.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "Memory.h"
44
#include <iostream>
55
#include <queue>
6-
6+
#include <vector>
77

88
Memory memory;
99
PCB* beingSwapped;
@@ -29,7 +29,7 @@ void swapOut(int &, int[], PCB *);
2929

3030
void startup()
3131
{
32-
//ontrace();
32+
ontrace();
3333
// Allows initialization of static system variables declared above.
3434
// Called once at start of the simulation.
3535
}
@@ -40,6 +40,8 @@ void startup()
4040
// See RUNNING A JOB, below, for additional information
4141
void Crint(int &a, int p[])
4242
{
43+
if (memory.getCount() + LTS.size() > 48)
44+
return;
4345
cout << "new job #" << p[1]<< endl;
4446
// Indicates the arrival of a new job on the drum.
4547
// At call: p [1] = job number
@@ -103,7 +105,7 @@ void Tro(int &a, int p[])
103105
runCurrentJob(a,p);
104106
}
105107
else
106-
a = 2;
108+
runCurrentJob(a,p);
107109
}
108110
void Svc(int &a, int p[])
109111
{

0 commit comments

Comments
 (0)