summaryrefslogtreecommitdiffstats
path: root/Modules/clinic
diff options
context:
space:
mode:
authorKumar Aditya <kumaraditya@python.org>2024-06-22 17:58:35 (GMT)
committerGitHub <noreply@github.com>2024-06-22 17:58:35 (GMT)
commit4717aaa1a72d1964f1531a7c613f37ce3d9056d9 (patch)
tree725e3b743d4ef707e89f5abe7804fce58fbd5036 /Modules/clinic
parente21347549535b16f51a39986b78a2c2cd4ed09f4 (diff)
downloadcpython-4717aaa1a72d1964f1531a7c613f37ce3d9056d9.zip
cpython-4717aaa1a72d1964f1531a7c613f37ce3d9056d9.tar.gz
cpython-4717aaa1a72d1964f1531a7c613f37ce3d9056d9.tar.bz2
GH-107803: double linked list implementation for asyncio tasks (GH-107804)
* linked list * add tail optmiization to linked list * wip * wip * wip * more fixes * finally it works * add tests * remove weakreflist * add some comments * reduce code duplication in _asynciomodule.c * address some review comments * add invariants about the state of the linked list * add better explanation * clinic regen * reorder branches for better branch prediction * Update Modules/_asynciomodule.c * Apply suggestions from code review Co-authored-by: Itamar Oren <itamarost@gmail.com> * fix capturing of eager tasks * add comment to task finalization * fix tests and couple c implmentation to c task improved linked-list logic and more comments * fix test --------- Co-authored-by: Itamar Oren <itamarost@gmail.com>
Diffstat (limited to 'Modules/clinic')
-rw-r--r--Modules/clinic/_asynciomodule.c.h62
1 files changed, 61 insertions, 1 deletions
diff --git a/Modules/clinic/_asynciomodule.c.h b/Modules/clinic/_asynciomodule.c.h
index 6a9c8ff..d619a12 100644
--- a/Modules/clinic/_asynciomodule.c.h
+++ b/Modules/clinic/_asynciomodule.c.h
@@ -1487,4 +1487,64 @@ skip_optional_pos:
exit:
return return_value;
}
-/*[clinic end generated code: output=b26155080c82c472 input=a9049054013a1b77]*/
+
+PyDoc_STRVAR(_asyncio_all_tasks__doc__,
+"all_tasks($module, /, loop=None)\n"
+"--\n"
+"\n"
+"Return a set of all tasks for the loop.");
+
+#define _ASYNCIO_ALL_TASKS_METHODDEF \
+ {"all_tasks", _PyCFunction_CAST(_asyncio_all_tasks), METH_FASTCALL|METH_KEYWORDS, _asyncio_all_tasks__doc__},
+
+static PyObject *
+_asyncio_all_tasks_impl(PyObject *module, PyObject *loop);
+
+static PyObject *
+_asyncio_all_tasks(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+ PyObject *return_value = NULL;
+ #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
+
+ #define NUM_KEYWORDS 1
+ static struct {
+ PyGC_Head _this_is_not_used;
+ PyObject_VAR_HEAD
+ PyObject *ob_item[NUM_KEYWORDS];
+ } _kwtuple = {
+ .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
+ .ob_item = { &_Py_ID(loop), },
+ };
+ #undef NUM_KEYWORDS
+ #define KWTUPLE (&_kwtuple.ob_base.ob_base)
+
+ #else // !Py_BUILD_CORE
+ # define KWTUPLE NULL
+ #endif // !Py_BUILD_CORE
+
+ static const char * const _keywords[] = {"loop", NULL};
+ static _PyArg_Parser _parser = {
+ .keywords = _keywords,
+ .fname = "all_tasks",
+ .kwtuple = KWTUPLE,
+ };
+ #undef KWTUPLE
+ PyObject *argsbuf[1];
+ Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
+ PyObject *loop = Py_None;
+
+ args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
+ if (!args) {
+ goto exit;
+ }
+ if (!noptargs) {
+ goto skip_optional_pos;
+ }
+ loop = args[0];
+skip_optional_pos:
+ return_value = _asyncio_all_tasks_impl(module, loop);
+
+exit:
+ return return_value;
+}
+/*[clinic end generated code: output=ffe9b71bc65888b3 input=a9049054013a1b77]*/