1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-26 01:18:28 +00:00

loop: use utimeq.discard()

This commit is contained in:
Jan Pochyla 2018-01-22 13:07:12 +01:00
parent aeab633090
commit 7960f3ad8e
2 changed files with 6 additions and 25 deletions

View File

@ -5,3 +5,4 @@ class utimeq:
def push(self, time: int, callback: Any, value: Any) -> None: ...
def pop(self, entry: List[Any]) -> None: ...
def peektime(self) -> int: ...
def discard(self, callback: Any) -> None: ...

View File

@ -37,37 +37,17 @@ def schedule(task, value=None, deadline=None):
_queue.push(deadline, task, value)
def unschedule(task):
'''
Remove task from the time queue. Cancels previous `schedule`.
'''
global _queue
task_entry = [0, 0, 0] # deadline, task, value
queue_copy = utimeq.utimeq(_QUEUE_SIZE)
while _queue:
_queue.pop(task_entry)
d, t, v = task_entry
if t is not task:
queue_copy.push(d, t, v)
_queue = queue_copy
def pause(task, iface):
tasks = _paused.get(iface, None)
if tasks is None:
tasks = _paused[iface] = []
tasks.append(task)
def unpause(task):
for iface in _paused:
if task in _paused[iface]:
_paused[iface].remove(task)
tasks = _paused[iface] = set()
tasks.add(task)
def close(task):
unschedule(task)
unpause(task)
for iface in _paused:
_paused[iface].discard(task)
_queue.discard(task)
task.close()