-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkQ.py
executable file
·74 lines (54 loc) · 1.65 KB
/
workQ.py
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
import operator
from Process import *
"""
workQ class which uses a list as an underlying implemetation.
Attributes: workQ -- List representing the Queue
"""
class workQ():
def __init__(self):
self.queue = []
def size(self):
return len(self.queue)
"""
This should reorganize the workQ based on the algorithm passed in
"""
def step(self, algorithm):
# Call right handler
if (algorithm == "FCFS"):
return self.__qFCFS()
elif (algorithm == "SRT"):
return self.__qSRT()
elif (algorithm == "RR"):
return self.__qRR()
else:
raise RuntimeError("BAD SCHEDULING ALGORITHM")
exit()
def isEmpty(self):
return len(self.queue) <= 0
def peak(self):
return self.queue[0]
"""
Add process to the workQ tail
"""
def enqueu(self, proc):
assert (isinstance(proc, Process))
self.queue.append(proc)
"""
Remove head from the Queue
"""
def dequeue(self):
return self.queue.pop(0)
def __repr__(self):
return str(vars(self))
################################################################################
# DONT SHOULD NOT BE INVOKED DIRECTLY
################################################################################
def __qFCFS(self):
# ENQUEUE and DEQUEUE already preserve FCFS Nature.. ? #FIXME
pass
def __qSRT(self):
self.queue.sort(key=operator.attrgetter("burstTimeLeft"))
def __qRR(self):
# TODO
pass
################################################################################