Commit 05c15eeb authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Jérome Perrin

OperatorPreemptive corrected

parent 2f71f199
...@@ -46,19 +46,22 @@ class OperatorPreemptive(Operator): ...@@ -46,19 +46,22 @@ class OperatorPreemptive(Operator):
def checkIfResourceIsAvailable(self,callerObject=None): def checkIfResourceIsAvailable(self,callerObject=None):
activeResource= self.getResource() activeResource= self.getResource()
activeResourceQueue = activeResource.getResourceQueue() activeResourceQueue = activeResource.getResourceQueue()
try: # find out which station is requesting the operator?
# read the station operated by the operator thecaller=callerObject
# if the operator is occupied return True
if len(activeResourceQueue)==0:
return True
# read the station currently operated by the operator
victim=activeResourceQueue[0] victim=activeResourceQueue[0]
# read its activeQ # read its activeQ
victimQueue=victim.getActiveObjectQueue() victimQueue=victim.getActiveObjectQueue()
# find out which station is requesting the operator? # if the callerObject is None then return False as the operator is occupied
thecaller=callerObject if thecaller==None:
return False
thecallerQueue=thecaller.getActiveObjectQueue() thecallerQueue=thecaller.getActiveObjectQueue()
#if the receiver is not empty and the caller is not empty
#if the receiver is not empty if len(victimQueue)>0 and len(theCallerQueue):
if len(victimQueue)>0: try:
# and the caller is not empty
if len(thecallerQueue)>0:
#if the Entity to be forwarded to the station currently processed by the operator is critical #if the Entity to be forwarded to the station currently processed by the operator is critical
if thecallerQueue[0].isCritical: if thecallerQueue[0].isCritical:
#if the receiver does not hold an Entity that is also critical #if the receiver does not hold an Entity that is also critical
...@@ -68,7 +71,7 @@ class OperatorPreemptive(Operator): ...@@ -68,7 +71,7 @@ class OperatorPreemptive(Operator):
victim.preempt() victim.preempt()
victim.timeLastEntityEnded=now() #required to count blockage correctly in the preemptied station victim.timeLastEntityEnded=now() #required to count blockage correctly in the preemptied station
return True return True
# if the operator is not occupied, or if the caller is None then perform the default behaviour # if the entity has no isCritical property then ran the default behaviour
except: except:
pass pass
return len(self.Res.activeQ)<self.capacity return len(self.Res.activeQ)<self.capacity
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment