/* Counter for autogenerated Task names */
uint64_t task_name_counter;
+#ifndef Py_GIL_DISABLED
futureiterobject *fi_freelist;
Py_ssize_t fi_freelist_len;
+#endif
/* Linked-list of all tasks which are instances of asyncio.Task or subclasses
of it. Third party tasks implementations which don't inherit from
assert(_PyType_HasFeature(tp, Py_TPFLAGS_HEAPTYPE));
- PyObject *module = ((PyHeapTypeObject*)tp)->ht_module;
- asyncio_state *state = NULL;
-
PyObject_GC_UnTrack(it);
tp->tp_clear((PyObject *)it);
+#ifndef Py_GIL_DISABLED
// GH-115874: We can't use PyType_GetModuleByDef here as the type might have
// already been cleared, which is also why we must check if ht_module != NULL.
+ PyObject *module = ((PyHeapTypeObject*)tp)->ht_module;
+ asyncio_state *state = NULL;
if (module && _PyModule_GetDef(module) == &_asynciomodule) {
state = get_asyncio_state(module);
}
it->future = (FutureObj*) state->fi_freelist;
state->fi_freelist = it;
}
- else {
+ else
+#endif
+ {
PyObject_GC_Del(it);
Py_DECREF(tp);
}
asyncio_state *state = get_asyncio_state_by_def((PyObject *)fut);
ENSURE_FUTURE_ALIVE(state, fut)
+#ifndef Py_GIL_DISABLED
if (state->fi_freelist_len) {
state->fi_freelist_len--;
it = state->fi_freelist;
it->future = NULL;
_Py_NewReference((PyObject*) it);
}
- else {
+ else
+#endif
+ {
it = PyObject_GC_New(futureiterobject, state->FutureIterType);
if (it == NULL) {
return NULL;
static void
module_free_freelists(asyncio_state *state)
{
+#ifndef Py_GIL_DISABLED
PyObject *next;
PyObject *current;
}
assert(state->fi_freelist_len == 0);
state->fi_freelist = NULL;
+#endif
}
static int
Py_VISIT(state->context_kwname);
+#ifndef Py_GIL_DISABLED
// Visit freelist.
PyObject *next = (PyObject*) state->fi_freelist;
while (next != NULL) {
Py_VISIT(current);
next = (PyObject*) ((futureiterobject*) current)->future;
}
+#endif
+
return 0;
}