From bf878ff15ee5a88dc7eabc4d118b5d462193fc3b Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Thu, 9 Feb 2017 13:49:10 +0100 Subject: [PATCH] trezor.loop: support re-using Sleep and Wait objects --- src/trezor/loop.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/trezor/loop.py b/src/trezor/loop.py index 12f5695e99..0c445615ea 100644 --- a/src/trezor/loop.py +++ b/src/trezor/loop.py @@ -159,10 +159,11 @@ class Sleep(Syscall): ''' def __init__(self, delay_us): - self.deadline = utime.ticks_add(utime.ticks_us(), delay_us) + self.delay_us = delay_us def handle(self, task): - schedule_task(task, self.deadline, self.deadline) + deadline = utime.ticks_add(utime.ticks_us(), self.delay_us) + schedule_task(task, deadline, deadline) class Select(Syscall): @@ -248,12 +249,13 @@ class Wait(Syscall): self.children = children self.wait_for = wait_for self.exit_others = exit_others - self.scheduled = [] - self.finished = [] + self.scheduled = None + self.finished = None self.callback = None def handle(self, task): self.callback = task + self.finished = [] self.scheduled = [self._wait(c) for c in self.children] for ct in self.scheduled: schedule_task(ct)