-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstComeFirstServedPolicy.cs
More file actions
95 lines (80 loc) · 2.97 KB
/
FirstComeFirstServedPolicy.cs
File metadata and controls
95 lines (80 loc) · 2.97 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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace Scheduling
{
class FirstComeFirstServedPolicy : SchedulingPolicy
{
List<int> FCFS_processes = new List<int>();
int curProcessId = 1;
public override int NextProcess(Dictionary<int, ProcessTableEntry> dProcessTable)
{
foreach (int processID in FCFS_processes)
{
if (!dProcessTable[processID].Done && !dProcessTable[processID].Blocked)
{
dProcessTable[processID].MaxStarvation++;
}
}
var curProcess = dProcessTable[curProcessId];
if (FCFS_processes.Count == 0)
return -1;
if (curProcessId == 1 && !curProcess.Blocked && !curProcess.Done && !curProcess.Yield)
{
return curProcessId;
}
if (curProcessId == FCFS_processes.Count()-1)
{
for (int i = 1; i < FCFS_processes.Count(); i++)
{
int nextProcessId = i;
var nextProcess = dProcessTable[nextProcessId];
if (!nextProcess.Done && !nextProcess.Blocked && !nextProcess.Yield)
{
curProcessId = nextProcessId;
nextProcess.MaxStarvation = 0;
return nextProcessId;
}
}
}
else
{
for (int i = curProcessId; i < FCFS_processes.Count()-1; i++)
{
int nextProcessId = i+1;
var nextProcess = dProcessTable[nextProcessId];
if (!nextProcess.Done && !nextProcess.Blocked && !nextProcess.Yield)
{
curProcessId = nextProcessId;
nextProcess.MaxStarvation = 0;
return nextProcessId;
}
}
}
curProcessId = 1;
for(int i = 1; i < FCFS_processes.Count(); i++)
{
int nextProcessId = i;
var nextProcess = dProcessTable[nextProcessId];
if (!nextProcess.Done && !nextProcess.Blocked && !nextProcess.Yield)
{
curProcessId = nextProcessId;
nextProcess.MaxStarvation = 0;
return nextProcessId;
}
}
return 0;
// return 0; // החזר את מזהה התהליך הנוכחי
}
public override void AddProcess(int iProcessId)
{
FCFS_processes.Add(iProcessId);
}
public override bool RescheduleAfterInterrupt()
{
return true;
}
}
}