@@ -23,7 +23,6 @@ typedef struct {
23
23
PyTypeObject * TaskStepMethWrapper_Type ;
24
24
PyTypeObject * FutureType ;
25
25
PyTypeObject * TaskType ;
26
- PyTypeObject * PyRunningLoopHolder_Type ;
27
26
28
27
PyObject * asyncio_mod ;
29
28
PyObject * context_kwname ;
@@ -59,8 +58,8 @@ typedef struct {
59
58
/* Imports from traceback. */
60
59
PyObject * traceback_extract_stack ;
61
60
62
- PyObject * cached_running_holder ; // Borrowed ref.
63
- volatile uint64_t cached_running_holder_tsid ;
61
+ PyObject * cached_running_loop ; // Borrowed reference
62
+ volatile uint64_t cached_running_loop_tsid ;
64
63
65
64
/* Counter for autogenerated Task names */
66
65
uint64_t task_name_counter ;
@@ -138,14 +137,6 @@ typedef struct {
138
137
PyObject * sw_arg ;
139
138
} TaskStepMethWrapper ;
140
139
141
- typedef struct {
142
- PyObject_HEAD
143
- PyObject * rl_loop ;
144
- #if defined(HAVE_GETPID ) && !defined(MS_WINDOWS )
145
- pid_t rl_pid ;
146
- #endif
147
- } PyRunningLoopHolder ;
148
-
149
140
150
141
#define Future_CheckExact (state , obj ) Py_IS_TYPE(obj, state->FutureType)
151
142
#define Task_CheckExact (state , obj ) Py_IS_TYPE(obj, state->TaskType)
@@ -165,8 +156,6 @@ class _asyncio.Future "FutureObj *" "&Future_Type"
165
156
/* Get FutureIter from Future */
166
157
static PyObject * future_new_iter (PyObject * );
167
158
168
- static PyRunningLoopHolder * new_running_loop_holder (asyncio_state * , PyObject * );
169
-
170
159
171
160
static int
172
161
_is_coroutine (asyncio_state * state , PyObject * coro )
@@ -264,11 +253,11 @@ get_running_loop(asyncio_state *state, PyObject **loop)
264
253
265
254
PyThreadState * ts = _PyThreadState_GET ();
266
255
uint64_t ts_id = PyThreadState_GetID (ts );
267
- if (state -> cached_running_holder_tsid == ts_id &&
268
- state -> cached_running_holder != NULL )
256
+ if (state -> cached_running_loop_tsid == ts_id &&
257
+ state -> cached_running_loop != NULL )
269
258
{
270
259
// Fast path, check the cache.
271
- rl = state -> cached_running_holder ; // borrowed
260
+ rl = state -> cached_running_loop ;
272
261
}
273
262
else {
274
263
PyObject * ts_dict = _PyThreadState_GetDict (ts ); // borrowed
@@ -287,27 +276,16 @@ get_running_loop(asyncio_state *state, PyObject **loop)
287
276
}
288
277
}
289
278
290
- state -> cached_running_holder = rl ; // borrowed
291
- state -> cached_running_holder_tsid = ts_id ;
279
+ state -> cached_running_loop = rl ;
280
+ state -> cached_running_loop_tsid = ts_id ;
292
281
}
293
282
294
- assert (Py_IS_TYPE (rl , state -> PyRunningLoopHolder_Type ));
295
- PyObject * running_loop = ((PyRunningLoopHolder * )rl )-> rl_loop ;
296
-
297
- if (running_loop == Py_None ) {
298
- goto not_found ;
299
- }
300
283
301
- #if defined(HAVE_GETPID ) && !defined(MS_WINDOWS )
302
- /* On Windows there is no getpid, but there is also no os.fork(),
303
- so there is no need for this check.
304
- */
305
- if (getpid () != ((PyRunningLoopHolder * )rl )-> rl_pid ) {
284
+ if (rl == Py_None ) {
306
285
goto not_found ;
307
286
}
308
- #endif
309
287
310
- * loop = Py_NewRef (running_loop );
288
+ * loop = Py_NewRef (rl );
311
289
return 0 ;
312
290
313
291
not_found :
@@ -335,22 +313,14 @@ set_running_loop(asyncio_state *state, PyObject *loop)
335
313
PyExc_RuntimeError , "thread-local storage is not available" );
336
314
return -1 ;
337
315
}
338
-
339
- PyRunningLoopHolder * rl = new_running_loop_holder (state , loop );
340
- if (rl == NULL ) {
341
- return -1 ;
342
- }
343
-
344
316
if (PyDict_SetItem (
345
- ts_dict , & _Py_ID (__asyncio_running_event_loop__ ), ( PyObject * ) rl ) < 0 )
317
+ ts_dict , & _Py_ID (__asyncio_running_event_loop__ ), loop ) < 0 )
346
318
{
347
- Py_DECREF (rl ); // will cleanup loop & current_pid
348
319
return -1 ;
349
320
}
350
- Py_DECREF (rl );
351
321
352
- state -> cached_running_holder = ( PyObject * ) rl ;
353
- state -> cached_running_holder_tsid = PyThreadState_GetID (tstate );
322
+ state -> cached_running_loop = loop ; // borrowed, kept alive by ts_dict
323
+ state -> cached_running_loop_tsid = PyThreadState_GetID (tstate );
354
324
355
325
return 0 ;
356
326
}
@@ -3344,79 +3314,6 @@ _asyncio__leave_task_impl(PyObject *module, PyObject *loop, PyObject *task)
3344
3314
}
3345
3315
3346
3316
3347
- /*********************** PyRunningLoopHolder ********************/
3348
-
3349
-
3350
- static PyRunningLoopHolder *
3351
- new_running_loop_holder (asyncio_state * state , PyObject * loop )
3352
- {
3353
- PyRunningLoopHolder * rl = PyObject_GC_New (
3354
- PyRunningLoopHolder , state -> PyRunningLoopHolder_Type );
3355
- if (rl == NULL ) {
3356
- return NULL ;
3357
- }
3358
-
3359
- #if defined(HAVE_GETPID ) && !defined(MS_WINDOWS )
3360
- rl -> rl_pid = getpid ();
3361
- #endif
3362
- rl -> rl_loop = Py_NewRef (loop );
3363
-
3364
- PyObject_GC_Track (rl );
3365
- return rl ;
3366
- }
3367
-
3368
-
3369
- static int
3370
- PyRunningLoopHolder_clear (PyRunningLoopHolder * rl )
3371
- {
3372
- Py_CLEAR (rl -> rl_loop );
3373
- return 0 ;
3374
- }
3375
-
3376
-
3377
- static int
3378
- PyRunningLoopHolder_traverse (PyRunningLoopHolder * rl , visitproc visit ,
3379
- void * arg )
3380
- {
3381
- Py_VISIT (Py_TYPE (rl ));
3382
- Py_VISIT (rl -> rl_loop );
3383
- return 0 ;
3384
- }
3385
-
3386
-
3387
- static void
3388
- PyRunningLoopHolder_tp_dealloc (PyRunningLoopHolder * rl )
3389
- {
3390
- asyncio_state * state = get_asyncio_state_by_def ((PyObject * )rl );
3391
- if (state -> cached_running_holder == (PyObject * )rl ) {
3392
- state -> cached_running_holder = NULL ;
3393
- }
3394
- PyTypeObject * tp = Py_TYPE (rl );
3395
- PyObject_GC_UnTrack (rl );
3396
- PyRunningLoopHolder_clear (rl );
3397
- PyObject_GC_Del (rl );
3398
- Py_DECREF (tp );
3399
- }
3400
-
3401
-
3402
- static PyType_Slot PyRunningLoopHolder_slots [] = {
3403
- {Py_tp_getattro , PyObject_GenericGetAttr },
3404
- {Py_tp_dealloc , (destructor )PyRunningLoopHolder_tp_dealloc },
3405
- {Py_tp_traverse , (traverseproc )PyRunningLoopHolder_traverse },
3406
- {Py_tp_clear , PyRunningLoopHolder_clear },
3407
- {0 , NULL },
3408
- };
3409
-
3410
-
3411
- static PyType_Spec PyRunningLoopHolder_spec = {
3412
- .name = "_asyncio._RunningLoopHolder" ,
3413
- .basicsize = sizeof (PyRunningLoopHolder ),
3414
- .slots = PyRunningLoopHolder_slots ,
3415
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
3416
- Py_TPFLAGS_IMMUTABLETYPE ),
3417
- };
3418
-
3419
-
3420
3317
/*********************** Module **************************/
3421
3318
3422
3319
@@ -3448,7 +3345,6 @@ module_traverse(PyObject *mod, visitproc visit, void *arg)
3448
3345
Py_VISIT (state -> TaskStepMethWrapper_Type );
3449
3346
Py_VISIT (state -> FutureType );
3450
3347
Py_VISIT (state -> TaskType );
3451
- Py_VISIT (state -> PyRunningLoopHolder_Type );
3452
3348
3453
3349
Py_VISIT (state -> asyncio_mod );
3454
3350
Py_VISIT (state -> traceback_extract_stack );
@@ -3486,7 +3382,6 @@ module_clear(PyObject *mod)
3486
3382
Py_CLEAR (state -> TaskStepMethWrapper_Type );
3487
3383
Py_CLEAR (state -> FutureType );
3488
3384
Py_CLEAR (state -> TaskType );
3489
- Py_CLEAR (state -> PyRunningLoopHolder_Type );
3490
3385
3491
3386
Py_CLEAR (state -> asyncio_mod );
3492
3387
Py_CLEAR (state -> traceback_extract_stack );
@@ -3625,7 +3520,6 @@ module_exec(PyObject *mod)
3625
3520
} while (0)
3626
3521
3627
3522
CREATE_TYPE (mod , state -> TaskStepMethWrapper_Type , & TaskStepMethWrapper_spec , NULL );
3628
- CREATE_TYPE (mod , state -> PyRunningLoopHolder_Type , & PyRunningLoopHolder_spec , NULL );
3629
3523
CREATE_TYPE (mod , state -> FutureIterType , & FutureIter_spec , NULL );
3630
3524
CREATE_TYPE (mod , state -> FutureType , & Future_spec , NULL );
3631
3525
CREATE_TYPE (mod , state -> TaskType , & Task_spec , state -> FutureType );
0 commit comments