Skip to content

Commit 5a64c43

Browse files
committed
Restore original comments.
1 parent 0def8d4 commit 5a64c43

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎Modules/_asynciomodule.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ typedef struct TaskObj {
6868
PyObject *task_context;
6969
struct llist_node task_node;
7070
#ifdef Py_GIL_DISABLED
71+
// thread id of the thread where this task was created
7172
uint64_t task_tstate_id;
7273
#endif
7374
} TaskObj;
@@ -2207,10 +2208,14 @@ unregister_task(TaskObj *task)
22072208
{
22082209
#ifdef Py_GIL_DISABLED
22092210
PyThreadState *tstate = _PyThreadState_GET();
2211+
// check if we are in the same thread
2212+
// if so, we can avoid locking
22102213
if (task->task_tstate_id == tstate->id && !tstate->_status.finalizing) {
22112214
unregister_task_safe(task);
22122215
}
22132216
else {
2217+
// we are in a different thread
2218+
// stop the world then check and remove the task
22142219
_PyEval_StopTheWorld(tstate->interp);
22152220
unregister_task_safe(task);
22162221
_PyEval_StartTheWorld(tstate->interp);

0 commit comments

Comments
 (0)