-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDispatcher.java
More file actions
42 lines (37 loc) · 1.55 KB
/
Dispatcher.java
File metadata and controls
42 lines (37 loc) · 1.55 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
class Dispatcher {
/**
* Dipatches a job onto a CPU.
* @param job The job to be loaded on to a CPU.
* @param cpu specifies which CPU the job will be loaded to.
*/
//Syncronized method allows the resources to be protected as they are running concurrently.
static synchronized void loadJob(PCB job, CPU cpu) {
int totalSize = job.getTotalSize();
int diskStartPoint = job.getDiskStart();
int ramStartPoint = accessRam(totalSize, diskStartPoint);
int ramEndPoint = ramStartPoint + totalSize;
job.setCurrrentCPU(cpu);
job.setRamStart(ramStartPoint);
job.setRamEnd(ramEndPoint);
// Load Instructions into memory
cpu.setRegisters(job.getRegisters());
cpu.resetProgramCounter();
cpu.setCurrent_Job(job);
job.setStartTime(System.currentTimeMillis());
System.out.println(job);
}
//syncronized method to hide memory resources as they are run concurrently.
static synchronized int accessRam(int totalSize, int diskStartPoint) {
int ramStartPoint = MMU.left(totalSize);
for(int i = ramStartPoint; i < ramStartPoint + totalSize; i++) {
MMU.store_ram(i, MMU.load_disk(diskStartPoint + i - ramStartPoint));
}
return ramStartPoint;
}
//clear when job is completed
static void unloadJob(PCB job, CPU cpu) {
job.setRegisters(cpu.getRegisters());
job.setCompletionTime(System.currentTimeMillis());
cpu.setCurrent_Job(null);
}
}