Add _PyThreadState_UncheckedGet() · python/cpython@bfd316e (original) (raw)
`@@ -3,6 +3,12 @@
`
3
3
``
4
4
`#include "Python.h"
`
5
5
``
``
6
`+
#ifndef Py_BUILD_CORE
`
``
7
`+
/* ensure that PyThreadState_GET() is a macro, not an alias to
`
``
8
`+
- PyThreadState_Get() */
`
``
9
`+
error "pystate.c must be compiled with Py_BUILD_CORE defined"
`
``
10
`+
#endif
`
``
11
+
6
12
`/* --------------------------------------------------------------------------
`
7
13
`CAUTION
`
8
14
``
`@@ -423,7 +429,7 @@ tstate_delete_common(PyThreadState *tstate)
`
423
429
`void
`
424
430
`PyThreadState_Delete(PyThreadState *tstate)
`
425
431
`{
`
426
``
`-
if (tstate == (PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current))
`
``
432
`+
if (tstate == PyThreadState_GET())
`
427
433
`Py_FatalError("PyThreadState_Delete: tstate is still current");
`
428
434
`#ifdef WITH_THREAD
`
429
435
`if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
`
`@@ -437,8 +443,7 @@ PyThreadState_Delete(PyThreadState *tstate)
`
437
443
`void
`
438
444
`PyThreadState_DeleteCurrent()
`
439
445
`{
`
440
``
`-
PyThreadState tstate = (PyThreadState)_Py_atomic_load_relaxed(
`
441
``
`-
&_PyThreadState_Current);
`
``
446
`+
PyThreadState *tstate = PyThreadState_GET();
`
442
447
`if (tstate == NULL)
`
443
448
`Py_FatalError(
`
444
449
`"PyThreadState_DeleteCurrent: no current tstate");
`
`@@ -488,11 +493,17 @@ _PyThreadState_DeleteExcept(PyThreadState *tstate)
`
488
493
`}
`
489
494
``
490
495
``
``
496
`+
PyThreadState *
`
``
497
`+
_PyThreadState_UncheckedGet(void)
`
``
498
`+
{
`
``
499
`+
return PyThreadState_GET();
`
``
500
`+
}
`
``
501
+
``
502
+
491
503
`PyThreadState *
`
492
504
`PyThreadState_Get(void)
`
493
505
`{
`
494
``
`-
PyThreadState tstate = (PyThreadState)_Py_atomic_load_relaxed(
`
495
``
`-
&_PyThreadState_Current);
`
``
506
`+
PyThreadState *tstate = PyThreadState_GET();
`
496
507
`if (tstate == NULL)
`
497
508
`Py_FatalError("PyThreadState_Get: no current thread");
`
498
509
``
`@@ -503,8 +514,7 @@ PyThreadState_Get(void)
`
503
514
`PyThreadState *
`
504
515
`PyThreadState_Swap(PyThreadState *newts)
`
505
516
`{
`
506
``
`-
PyThreadState oldts = (PyThreadState)_Py_atomic_load_relaxed(
`
507
``
`-
&_PyThreadState_Current);
`
``
517
`+
PyThreadState *oldts = PyThreadState_GET();
`
508
518
``
509
519
`_Py_atomic_store_relaxed(&_PyThreadState_Current, newts);
`
510
520
`/* It should not be possible for more than one thread state
`
`@@ -535,8 +545,7 @@ PyThreadState_Swap(PyThreadState *newts)
`
535
545
`PyObject *
`
536
546
`PyThreadState_GetDict(void)
`
537
547
`{
`
538
``
`-
PyThreadState tstate = (PyThreadState)_Py_atomic_load_relaxed(
`
539
``
`-
&_PyThreadState_Current);
`
``
548
`+
PyThreadState *tstate = PyThreadState_GET();
`
540
549
`if (tstate == NULL)
`
541
550
`return NULL;
`
542
551
``
`@@ -682,7 +691,7 @@ PyThreadState_IsCurrent(PyThreadState *tstate)
`
682
691
`{
`
683
692
`/* Must be the tstate for this thread */
`
684
693
`assert(PyGILState_GetThisThreadState()==tstate);
`
685
``
`-
return tstate == (PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current);
`
``
694
`+
return tstate == PyThreadState_GET();
`
686
695
`}
`
687
696
``
688
697
`/* Internal initialization/finalization functions called by
`
`@@ -774,9 +783,7 @@ PyGILState_GetThisThreadState(void)
`
774
783
`int
`
775
784
`PyGILState_Check(void)
`
776
785
`{
`
777
``
`-
/* can't use PyThreadState_Get() since it will assert that it has the GIL */
`
778
``
`-
PyThreadState tstate = (PyThreadState)_Py_atomic_load_relaxed(
`
779
``
`-
&_PyThreadState_Current);
`
``
786
`+
PyThreadState *tstate = PyThreadState_GET();
`
780
787
`return tstate && (tstate == PyGILState_GetThisThreadState());
`
781
788
`}
`
782
789
``