actorlib/sim: use set instead of list to represent active transactions

This commit is contained in:
Sebastien Bourdeauducq 2012-06-08 17:56:52 +02:00
parent 910c7806cf
commit 152a7e282e
1 changed files with 10 additions and 9 deletions

View File

@ -15,34 +15,33 @@ class Token:
class SimActor(Actor): class SimActor(Actor):
def __init__(self, generator, *endpoint_descriptions, **misc): def __init__(self, generator, *endpoint_descriptions, **misc):
self.generator = generator self.generator = generator
self.active = [] # TODO: use set self.active = set()
self.done = False self.done = False
super().__init__(*endpoint_descriptions, **misc) super().__init__(*endpoint_descriptions, **misc)
def _process_transactions(self, s): def _process_transactions(self, s):
completed = [] completed = set()
for token in self.active: for token in self.active:
ep = self.endpoints[token.endpoint] ep = self.endpoints[token.endpoint]
if isinstance(ep, Sink): if isinstance(ep, Sink):
if s.rd(ep.ack): if s.rd(ep.ack):
if s.rd(ep.stb): if s.rd(ep.stb):
token.value = s.multiread(ep.token) token.value = s.multiread(ep.token)
completed.append(token) completed.add(token)
s.wr(ep.ack, 0) s.wr(ep.ack, 0)
else: else:
s.wr(ep.ack, 1) s.wr(ep.ack, 1)
elif isinstance(ep, Source): elif isinstance(ep, Source):
if s.rd(ep.stb): if s.rd(ep.stb):
if s.rd(ep.ack): if s.rd(ep.ack):
completed.append(token) completed.add(token)
s.wr(ep.stb, 0) s.wr(ep.stb, 0)
else: else:
s.wr(ep.stb, 1) s.wr(ep.stb, 1)
s.multiwrite(ep.token, token.value) s.multiwrite(ep.token, token.value)
else: else:
raise TypeError raise TypeError
for token in completed: # XXX self.active -= completed
self.active.remove(token)
def _next_transactions(self): def _next_transactions(self):
try: try:
@ -51,9 +50,11 @@ class SimActor(Actor):
self.done = True self.done = True
transactions = None transactions = None
if isinstance(transactions, Token): if isinstance(transactions, Token):
self.active = [transactions] self.active = {transactions}
elif isinstance(transactions, tuple) or isinstance(transactions, list): elif isinstance(transactions, tuple) \
self.active = list(transactions) or isinstance(transactions, list) \
or isinstance(transactions, set):
self.active = set(transactions)
elif transactions is None: elif transactions is None:
self.active = [] self.active = []
else: else: