summaryrefslogtreecommitdiffstatshomepage
path: root/extmod/uasyncio/core.py
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-04-20 17:20:07 +1000
committerDamien George <damien@micropython.org>2022-04-22 16:37:02 +1000
commitcaaff940a265bd30cca5a271b49e7addaf05ef53 (patch)
tree7413f84e38feee120173b6ea9d65ed3f3aae79f4 /extmod/uasyncio/core.py
parent28e7e15c0ad03f406cc5214f22d9a90a560f65c4 (diff)
downloadmicropython-caaff940a265bd30cca5a271b49e7addaf05ef53.tar.gz
micropython-caaff940a265bd30cca5a271b49e7addaf05ef53.zip
extmod/uasyncio: Rename and merge TaskQueue push/pop methods.
These are internal names and can be safely renamed without affecting user code. push_sorted() and push_head() are merged into a single push() method, which is already how the C version is implemented. pop_head() is simply renamed to pop(). The changes are: - q.push_sorted(task, t) -> q.push(task, t) - q.push_head(task) -> q.push(task) - q.pop_head() -> q.pop() The shorter names and removal of push_head() leads to a code size reduction of between 40 and 64 bytes on bare-metal targets. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'extmod/uasyncio/core.py')
-rw-r--r--extmod/uasyncio/core.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/extmod/uasyncio/core.py b/extmod/uasyncio/core.py
index 28b5e960ac..10a310809c 100644
--- a/extmod/uasyncio/core.py
+++ b/extmod/uasyncio/core.py
@@ -41,7 +41,7 @@ class SingletonGenerator:
def __next__(self):
if self.state is not None:
- _task_queue.push_sorted(cur_task, self.state)
+ _task_queue.push(cur_task, self.state)
self.state = None
return None
else:
@@ -115,11 +115,11 @@ class IOQueue:
# print('poll', s, sm, ev)
if ev & ~select.POLLOUT and sm[0] is not None:
# POLLIN or error
- _task_queue.push_head(sm[0])
+ _task_queue.push(sm[0])
sm[0] = None
if ev & ~select.POLLIN and sm[1] is not None:
# POLLOUT or error
- _task_queue.push_head(sm[1])
+ _task_queue.push(sm[1])
sm[1] = None
if sm[0] is None and sm[1] is None:
self._dequeue(s)
@@ -142,7 +142,7 @@ def create_task(coro):
if not hasattr(coro, "send"):
raise TypeError("coroutine expected")
t = Task(coro, globals())
- _task_queue.push_head(t)
+ _task_queue.push(t)
return t
@@ -167,7 +167,7 @@ def run_until_complete(main_task=None):
_io_queue.wait_io_event(dt)
# Get next task to run and continue it
- t = _task_queue.pop_head()
+ t = _task_queue.pop()
cur_task = t
try:
# Continue running the coroutine, it's responsible for rescheduling itself
@@ -203,7 +203,7 @@ def run_until_complete(main_task=None):
else:
# Schedule any other tasks waiting on the completion of this task.
while t.state.peek():
- _task_queue.push_head(t.state.pop_head())
+ _task_queue.push(t.state.pop())
waiting = True
# "False" indicates that the task is complete and has been await'ed on.
t.state = False
@@ -211,7 +211,7 @@ def run_until_complete(main_task=None):
# An exception ended this detached task, so queue it for later
# execution to handle the uncaught exception if no other task retrieves
# the exception in the meantime (this is handled by Task.throw).
- _task_queue.push_head(t)
+ _task_queue.push(t)
# Save return value of coro to pass up to caller.
t.data = er
elif t.state is None:
@@ -256,7 +256,7 @@ class Loop:
def stop():
global _stop_task
if _stop_task is not None:
- _task_queue.push_head(_stop_task)
+ _task_queue.push(_stop_task)
# If stop() is called again, do nothing
_stop_task = None