Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cc66eeb
linked list
kumaraditya303 May 24, 2023
d5a3d87
add tail optmiization to linked list
kumaraditya303 May 26, 2023
a0c5fcf
wip
kumaraditya303 May 26, 2023
77d012f
wip
kumaraditya303 May 28, 2023
5d9653d
wip
kumaraditya303 May 28, 2023
5a00198
Merge branch 'main' of https://github.com/python/cpython into linked-…
kumaraditya303 Jun 16, 2023
4cdc834
Merge branch 'main' of https://github.com/python/cpython into linked-…
kumaraditya303 Aug 2, 2023
35a00f1
more fixes
kumaraditya303 Aug 2, 2023
fddb9d6
Merge branch 'main' of https://github.com/python/cpython into linked-…
kumaraditya303 Aug 5, 2023
1d32835
finally it works
kumaraditya303 Aug 5, 2023
b46bcfe
Merge branch 'main' of https://github.com/python/cpython into linked-…
kumaraditya303 Aug 8, 2023
ee7ead2
Merge branch 'main' of https://github.com/python/cpython into linked-…
kumaraditya303 Aug 9, 2023
af0280a
add tests
kumaraditya303 Aug 9, 2023
999fff7
remove weakreflist
kumaraditya303 Aug 10, 2023
87a2231
add some comments
kumaraditya303 Aug 10, 2023
1812408
Merge branch 'main' of https://github.com/python/cpython into linked-…
kumaraditya303 Aug 12, 2023
3cb5673
Merge branch 'main' of https://github.com/python/cpython into linked-…
kumaraditya303 Aug 15, 2023
9552636
reduce code duplication in _asynciomodule.c
kumaraditya303 Aug 15, 2023
5c5b559
address some review comments
kumaraditya303 Aug 17, 2023
82cf69b
add invariants about the state of the linked list
kumaraditya303 Aug 17, 2023
8998f6a
add better explanation
kumaraditya303 Aug 17, 2023
d93c4e1
clinic regen
kumaraditya303 Aug 17, 2023
35726d9
reorder branches for better branch prediction
kumaraditya303 Aug 17, 2023
8dd0492
Update Modules/_asynciomodule.c
kumaraditya303 Aug 18, 2023
8325302
Apply suggestions from code review
kumaraditya303 Aug 19, 2023
80b65e0
fix capturing of eager tasks
kumaraditya303 Aug 19, 2023
b67649e
add comment to task finalization
kumaraditya303 Aug 20, 2023
1252b2f
Merge branch 'main' of https://github.com/python/cpython into linked-…
kumaraditya303 Aug 20, 2023
457739a
Merge branch 'main' into linked-list
kumaraditya303 Aug 20, 2023
4670731
Merge branch 'main' of https://github.com/python/cpython into linked-…
kumaraditya303 Aug 24, 2023
e061081
fix tests and couple c implmentation to c task
kumaraditya303 Aug 24, 2023
836d254
Merge branch 'main' of https://github.com/python/cpython into linked-…
kumaraditya303 Aug 30, 2023
efce4b3
fix test
kumaraditya303 Aug 30, 2023
c7b604c
Merge branch 'main' of https://github.com/python/cpython into linked-…
kumaraditya303 Jun 21, 2024
56beb04
Merge branch 'main' of https://github.com/python/cpython into linked-…
kumaraditya303 Jun 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tests and couple c implmentation to c task
improved linked-list logic and more comments
  • Loading branch information
kumaraditya303 committed Aug 24, 2023
commit e06108198d7dfe40fdf8c8f81aa137df02c9cfa7
6 changes: 3 additions & 3 deletions Lib/test/test_asyncio/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2678,7 +2678,7 @@ class PyTask_CFutureSubclass_Tests(BaseTaskTests, test_utils.TestCase):

Future = getattr(futures, '_CFuture', None)
Task = tasks._PyTask
all_tasks = getattr(tasks, '_py_all_tasks', None)
all_tasks = tasks._py_all_tasks


@unittest.skipUnless(hasattr(tasks, '_CTask'),
Expand All @@ -2696,15 +2696,15 @@ class PyTask_CFuture_Tests(BaseTaskTests, test_utils.TestCase):

Task = tasks._PyTask
Future = getattr(futures, '_CFuture', None)
all_tasks = getattr(tasks, '_c_all_tasks', None)
all_tasks = staticmethod(tasks._py_all_tasks)


class PyTask_PyFuture_Tests(BaseTaskTests, SetMethodsTest,
Comment thread
kumaraditya303 marked this conversation as resolved.
test_utils.TestCase):

Task = tasks._PyTask
Future = futures._PyFuture
all_tasks = asyncio.all_tasks
all_tasks = staticmethod(tasks._py_all_tasks)


@add_subclass_tests
Expand Down
46 changes: 24 additions & 22 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,26 +145,27 @@ typedef struct {

* After adding the first task 'task1':
- asyncio_tasks.head == task1
- task1->prev == &asyncio_tasks.tail
- task1->next == NULL
- asyncio_tasks.tail.next == task1
- task1->next == &asyncio_tasks.tail
- task1->prev == NULL
- asyncio_tasks.tail.prev == task1

* After adding a second task 'task2':
- asyncio_tasks.head == task2
- task2->prev == task1
- task2->next == NULL
- task1->next == task2
- asyncio_tasks.tail.next == task1
- task2->next == task1
- task2->prev == NULL
- task1->prev == task2
- asyncio_tasks.tail.prev == task1

* After removing task 'task1':
- asyncio_tasks.head == task2
- task2->prev == &asyncio_tasks.tail
- task2->next == NULL
- asyncio_tasks.tail.next == task2
- task2->next == &asyncio_tasks.tail
- task2->prev == NULL
- asyncio_tasks.tail.prev == task2

* After removing task 'task2', the list is empty:
- asyncio_tasks.head == &asyncio_tasks.tail
- asyncio_tasks.head->prev == NULL
- asyncio_tasks.tail.prev == NULL
- asyncio_tasks.tail.next == NULL
*/

Expand Down Expand Up @@ -1987,15 +1988,15 @@ register_task(asyncio_state *state, TaskObj *task)
{
assert(Task_Check(state, task));
Comment thread
kumaraditya303 marked this conversation as resolved.
assert(task != &state->asyncio_tasks.tail);
if (task->prev != NULL) {
if (task->next != NULL) {
// already registered
return;
}
assert(task->next == NULL);
assert(task->prev == NULL);
Comment thread
kumaraditya303 marked this conversation as resolved.
assert(state->asyncio_tasks.head != NULL);

task->prev = state->asyncio_tasks.head;
state->asyncio_tasks.head->next = task;
task->next = state->asyncio_tasks.head;
state->asyncio_tasks.head->prev = task;
state->asyncio_tasks.head = task;
}

Expand All @@ -2010,18 +2011,18 @@ unregister_task(asyncio_state *state, TaskObj *task)
{
assert(Task_Check(state, task));
assert(task != &state->asyncio_tasks.tail);
if (task->prev == NULL) {
if (task->next == NULL) {
// not registered
assert(task->next == NULL);
assert(task->prev == NULL);
assert(state->asyncio_tasks.head != task);
return;
}
task->prev->next = task->next;
if (task->next == NULL) {
task->next->prev = task->prev;
if (task->prev == NULL) {
assert(state->asyncio_tasks.head == task);
state->asyncio_tasks.head = task->prev;
state->asyncio_tasks.head = task->next;
} else {
task->next->prev = task->prev;
task->prev->next = task->next;
}
task->next = NULL;
task->prev = NULL;
Expand Down Expand Up @@ -3690,7 +3691,7 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop)
Py_DECREF(eager_iter);
TaskObj *head = state->asyncio_tasks.head;
assert(head != NULL);
assert(head->next == NULL);
assert(head->prev == NULL);
TaskObj *tail = &state->asyncio_tasks.tail;
while (head != tail)
{
Expand All @@ -3699,7 +3700,8 @@ _asyncio_all_tasks_impl(PyObject *module, PyObject *loop)
Py_DECREF(loop);
return NULL;
}
head = head->prev;
head = head->next;
assert(head != NULL);
}
PyObject *scheduled_iter = PyObject_GetIter(state->non_asyncio_tasks);
if (scheduled_iter == NULL) {
Expand Down