|
3 | 3 | #include "pycore_opcode_metadata.h" // _PyOpcode_Caches |
4 | 4 | #include "pycore_pyatomic_ft_wrappers.h" |
5 | 5 | #include "pycore_pylifecycle.h" // _PyOS_URandomNonblock() |
| 6 | +#include "pycore_tstate.h" |
6 | 7 | #include "pycore_uop_metadata.h" // _PyOpcode_uop_name |
7 | 8 | #include "pycore_uop_ids.h" // MAX_UOP_ID |
8 | 9 | #include "pycore_pystate.h" // _PyThreadState_GET() |
|
12 | 13 |
|
13 | 14 | #ifdef Py_STATS |
14 | 15 |
|
15 | | -// Pointer to Thread-local stats structure, null if recording is off. |
16 | | -_Py_thread_local PyStats *_Py_tss_stats; |
17 | | - |
18 | 16 | PyStats * |
19 | 17 | _PyStats_GetLocal(void) |
20 | 18 | { |
21 | | - return _Py_tss_stats; |
| 19 | + PyThreadState *tstate = _PyThreadState_GET(); |
| 20 | + if (tstate) { |
| 21 | + return tstate->pystats; |
| 22 | + } |
| 23 | + return NULL; |
22 | 24 | } |
23 | 25 |
|
24 | 26 | #ifdef Py_GIL_DISABLED |
@@ -582,20 +584,18 @@ stats_toggle_on_off(PyThreadState *tstate, int on) |
582 | 584 | if (!ts->_status.active) { |
583 | 585 | continue; |
584 | 586 | } |
585 | | - _PyThreadStateImpl *ts_impl = (_PyThreadStateImpl *)ts; |
586 | 587 | PyStats *s; |
587 | 588 | if (interp->pystats_enabled) { |
588 | 589 | #ifdef Py_GIL_DISABLED |
589 | | - s = ts_impl->pystats_struct; |
| 590 | + s = ((_PyThreadStateImpl *)ts)->pystats_struct; |
590 | 591 | #else |
591 | 592 | s = ((PyThreadState *)tstate)->interp->pystats_struct; |
592 | 593 | #endif |
593 | 594 | } |
594 | 595 | else { |
595 | 596 | s = NULL; |
596 | 597 | } |
597 | | - // write to the tss variable for the 'ts' thread |
598 | | - *ts_impl->pystats_tss = s; |
| 598 | + ts->pystats = s; |
599 | 599 | } |
600 | 600 | _PyEval_StartTheWorld(interp); |
601 | 601 | return 0; |
@@ -759,31 +759,28 @@ _PyStats_ThreadFini(_PyThreadStateImpl *tstate) |
759 | 759 | } |
760 | 760 |
|
761 | 761 | void |
762 | | -_PyStats_Attach(_PyThreadStateImpl *tstate) |
| 762 | +_PyStats_Attach(_PyThreadStateImpl *tstate_impl) |
763 | 763 | { |
764 | 764 | PyStats *s; |
765 | | - PyInterpreterState *interp = ((PyThreadState *)tstate)->interp; |
| 765 | + PyThreadState *tstate = (PyThreadState *)tstate_impl; |
| 766 | + PyInterpreterState *interp = tstate->interp; |
766 | 767 | if (FT_ATOMIC_LOAD_INT_RELAXED(interp->pystats_enabled)) { |
767 | 768 | #ifdef Py_GIL_DISABLED |
768 | | - s = tstate->pystats_struct; |
| 769 | + s = ((_PyThreadStateImpl *)tstate)->pystats_struct; |
769 | 770 | #else |
770 | | - s = ((PyThreadState *)tstate)->interp->pystats_struct; |
| 771 | + s = tstate->interp->pystats_struct; |
771 | 772 | #endif |
772 | 773 | } |
773 | 774 | else { |
774 | 775 | s = NULL; |
775 | 776 | } |
776 | | - // use correct TSS variable for thread |
777 | | - tstate->pystats_tss = &_Py_tss_stats; |
778 | | - // write to the tss variable for the 'ts' thread |
779 | | - _Py_tss_stats = s; |
| 777 | + tstate->pystats = s; |
780 | 778 | } |
781 | 779 |
|
782 | 780 | void |
783 | | -_PyStats_Detach(_PyThreadStateImpl *tstate) |
| 781 | +_PyStats_Detach(_PyThreadStateImpl *tstate_impl) |
784 | 782 | { |
785 | | - tstate->pystats_tss = NULL; |
786 | | - _Py_tss_stats = NULL; |
| 783 | + ((PyThreadState *)tstate_impl)->pystats = NULL; |
787 | 784 | } |
788 | 785 |
|
789 | 786 | #endif // Py_STATS |
0 commit comments