-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemQueue.java
More file actions
42 lines (35 loc) · 842 Bytes
/
MemQueue.java
File metadata and controls
42 lines (35 loc) · 842 Bytes
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
import java.util.LinkedList;
public class MemQueue {
static LinkedList <Process> waiting = new LinkedList<Process>();
static int current_free_memory;
static
{
current_free_memory=SystemConfig.memory;
}
static void enqueue(Process proc)
{
waiting.addLast(proc);
}
static void update(){
for(Process proc : waiting)
{
CpuSpec currcpuspec = (CpuSpec)proc.specifications.getFirst();
if(current_free_memory>currcpuspec.mem_req)
{
waiting.remove(proc);
PCB.addtoQueue(proc.tableIndex,0);
updateCurrentFreeMem(currcpuspec.mem_req,-1);
break;
}
}
}
static void updateCurrentFreeMem(int size,int incr)
{
if(incr==1)
current_free_memory+=size;
else if(incr==-1)
current_free_memory-=size;
else
System.out.print("Increment Error");
}
}