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

OperatorPreemptive corrected

parent 2f71f199
...@@ -46,29 +46,32 @@ class OperatorPreemptive(Operator): ...@@ -46,29 +46,32 @@ 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
victim=activeResourceQueue[0] # if the operator is occupied return True
# read its activeQ if len(activeResourceQueue)==0:
victimQueue=victim.getActiveObjectQueue() return True
# find out which station is requesting the operator? # read the station currently operated by the operator
thecaller=callerObject victim=activeResourceQueue[0]
thecallerQueue=thecaller.getActiveObjectQueue() # read its activeQ
victimQueue=victim.getActiveObjectQueue()
#if the receiver is not empty # if the callerObject is None then return False as the operator is occupied
if len(victimQueue)>0: if thecaller==None:
# and the caller is not empty return False
if len(thecallerQueue)>0: thecallerQueue=thecaller.getActiveObjectQueue()
#if the Entity to be forwarded to the station currently processed by the operator is critical #if the receiver is not empty and the caller is not empty
if thecallerQueue[0].isCritical: if len(victimQueue)>0 and len(theCallerQueue):
#if the receiver does not hold an Entity that is also critical try:
if not victimQueue[0].isCritical: #if the Entity to be forwarded to the station currently processed by the operator is critical
# then the receiver must be preemptied before it can receive any entities from the calerObject if thecallerQueue[0].isCritical:
victim.shouldPreempt=True #if the receiver does not hold an Entity that is also critical
victim.preempt() if not victimQueue[0].isCritical:
victim.timeLastEntityEnded=now() #required to count blockage correctly in the preemptied station # then the receiver must be preemptied before it can receive any entities from the calerObject
return True victim.shouldPreempt=True
# if the operator is not occupied, or if the caller is None then perform the default behaviour victim.preempt()
except: victim.timeLastEntityEnded=now() #required to count blockage correctly in the preemptied station
pass return True
# if the entity has no isCritical property then ran the default behaviour
except:
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