@@ -293,6 +293,8 @@ get_running_loop(asyncio_state *state, PyObject **loop)
293
293
}
294
294
}
295
295
296
+ // TODO GH-121621: This should be moved to PyThreadState
297
+ // for easier and quicker access.
296
298
state -> cached_running_loop = rl ;
297
299
state -> cached_running_loop_tsid = ts_id ;
298
300
}
@@ -336,6 +338,9 @@ set_running_loop(asyncio_state *state, PyObject *loop)
336
338
return -1 ;
337
339
}
338
340
341
+
342
+ // TODO GH-121621: This should be moved to PyThreadState
343
+ // for easier and quicker access.
339
344
state -> cached_running_loop = loop ; // borrowed, kept alive by ts_dict
340
345
state -> cached_running_loop_tsid = PyThreadState_GetID (tstate );
341
346
@@ -1616,6 +1621,7 @@ FutureIter_dealloc(futureiterobject *it)
1616
1621
state = get_asyncio_state (module );
1617
1622
}
1618
1623
1624
+ // TODO GH-121621: This should be moved to thread state as well.
1619
1625
if (state && state -> fi_freelist_len < FI_FREELIST_MAXLEN ) {
1620
1626
state -> fi_freelist_len ++ ;
1621
1627
it -> future = (FutureObj * ) state -> fi_freelist ;
@@ -2146,7 +2152,12 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
2146
2152
// optimization: defer task name formatting
2147
2153
// store the task counter as PyLong in the name
2148
2154
// for deferred formatting in get_name
2149
- name = PyLong_FromUnsignedLongLong (++ state -> task_name_counter );
2155
+ #ifdef Py_GIL_DISABLED
2156
+ unsigned long long counter = _Py_atomic_add_uint64 (& state -> task_name_counter , 1 ) + 1 ;
2157
+ #else
2158
+ unsigned long long counter = ++ state -> task_name_counter ;
2159
+ #endif
2160
+ name = PyLong_FromUnsignedLongLong (counter );
2150
2161
} else if (!PyUnicode_CheckExact (name )) {
2151
2162
name = PyObject_Str (name );
2152
2163
} else {
0 commit comments