diff --git a/mocks/utimeq.py b/mocks/utimeq.py index 17bf8809ba..c18f5828ac 100644 --- a/mocks/utimeq.py +++ b/mocks/utimeq.py @@ -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: ... diff --git a/src/trezor/loop.py b/src/trezor/loop.py index 91abe96c99..6bbce18e06 100644 --- a/src/trezor/loop.py +++ b/src/trezor/loop.py @@ -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()