-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPCB.java
More file actions
145 lines (133 loc) · 4.23 KB
/
PCB.java
File metadata and controls
145 lines (133 loc) · 4.23 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import java.util.ArrayList;
import java.util.LinkedList;
public class PCB{
// nextPid determines the next id of the next pcb
private static int nextPid = 0;
// stores the pcb
private int PID;
// Storage of VFSIds coordinates
private int[] VFSIds = new int[10];
// up stores the userlandProcess
private UserLandProcess up;
// priority stores the pcb priority
private OS.Priority priority;
// demote used to demote the process.
private int demote = 0;
// sleepTime stores the sleep time to wake up
private long sleepTime;
// origTime used for debugging purposes
private long origTime;
private String name;
private LinkedList<KernelMessage> messageList = new LinkedList<KernelMessage>();
private boolean isWaitingForMessage = false;
// The virtual page number will be the index into the array, the value in the array will be the physical page number.
private VirtualToPhysicalMapping[] virtualToPhysicalMappings = new VirtualToPhysicalMapping[100];
// PCB constructor initializes the pcb and sets up up and PID
public PCB(UserLandProcess up){
this.up = up;
name = up.getClass().getSimpleName();
PID = nextPid++;
for(int i = 0; i < VFSIds.length; i++)
VFSIds[i] = -1;
// for(int i = 0; i < virtualPageNumbers.length; i++)
// virtualPageNumbers[i] = -1;
}
// iSDone checks to see if up is finished
public boolean isDone(){
return up.isDone();
}
// start starts the pcb
public void start(){
up.start();
}
// stop stops the pcb, checks to see if stopped and is then stopped.
public void stop() {
up.stop();
}
// returns ulp
public UserLandProcess getProcess(){
return up;
}
// priority mutator
public OS.Priority getPriority(){
return priority;
}
public void setPriority(OS.Priority p){
priority = p;
}
// pid mutator
public int getPid(){
return PID;
}
// demote adds one to demote
public void demote(){
demote++;
}
// demote mutator
public int getDemote(){
return demote;
}
// sets demote to 0
public void resetDemote(){
demote = 0;
}
// original time set
public void setOrigTime(long origTime){
this.origTime = origTime;
}
// original time mutator
public long getOrigTime(){
return origTime;
}
public void setSleepTime(long sleepTime){
this.sleepTime = sleepTime;
}
// returns sleeptime
public long getSleepTime(){
return sleepTime;
}
public String getName(){return name;}
public int[] getVFSIds() {
return VFSIds;
}
public void setVFSIds(int[] VFSIds) {
this.VFSIds = VFSIds;
}
public void appendToMessageList(KernelMessage km){
messageList.add(km);
}
public boolean isNotOccupied(){
return messageList.isEmpty();
}
public KernelMessage popMessageList(){
return messageList.pop();
}
public boolean isWaitingForMessage() {
return isWaitingForMessage;
}
public void setWaitingForMessage(boolean waitingForMessage) {
isWaitingForMessage = waitingForMessage;
}
// addPhysicalAddress adds to the next available virtualPageNumber.
public int addPhysicalAddress(int PhysicalAddress){
int i = 0;
while(virtualToPhysicalMappings[i] != null)
i++;
virtualToPhysicalMappings[i] = new VirtualToPhysicalMapping();
virtualToPhysicalMappings[i].PhysicalPageNumber = PhysicalAddress;
return i;
}
public void initMapping(){
int i = 0;
while(virtualToPhysicalMappings[i] != null)
i++;
virtualToPhysicalMappings[i] = new VirtualToPhysicalMapping();
}
// Getter/setter for virtualPageNumbers
public VirtualToPhysicalMapping[] getVirtualToPhysicalMappings() {
return virtualToPhysicalMappings;
}
public void setVirtualToPhysicalMappings(VirtualToPhysicalMapping[] vpms) {
this.virtualToPhysicalMappings = vpms;
}
}