mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-120838: Add _PyThreadState_WHENCE_FINI (gh-121010)
We also add _PyThreadState_NewBound() and drop _PyThreadState_SetWhence(). This change only affects internal API.
This commit is contained in:
parent
769aea3329
commit
a905721b9c
8 changed files with 27 additions and 27 deletions
|
@ -97,10 +97,11 @@ struct _ts {
|
||||||
#ifdef Py_BUILD_CORE
|
#ifdef Py_BUILD_CORE
|
||||||
# define _PyThreadState_WHENCE_NOTSET -1
|
# define _PyThreadState_WHENCE_NOTSET -1
|
||||||
# define _PyThreadState_WHENCE_UNKNOWN 0
|
# define _PyThreadState_WHENCE_UNKNOWN 0
|
||||||
# define _PyThreadState_WHENCE_INTERP 1
|
# define _PyThreadState_WHENCE_INIT 1
|
||||||
# define _PyThreadState_WHENCE_THREADING 2
|
# define _PyThreadState_WHENCE_FINI 2
|
||||||
# define _PyThreadState_WHENCE_GILSTATE 3
|
# define _PyThreadState_WHENCE_THREADING 3
|
||||||
# define _PyThreadState_WHENCE_EXEC 4
|
# define _PyThreadState_WHENCE_GILSTATE 4
|
||||||
|
# define _PyThreadState_WHENCE_EXEC 5
|
||||||
#endif
|
#endif
|
||||||
int _whence;
|
int _whence;
|
||||||
|
|
||||||
|
|
|
@ -217,10 +217,14 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) {
|
||||||
|
|
||||||
// PyThreadState functions
|
// PyThreadState functions
|
||||||
|
|
||||||
extern PyThreadState * _PyThreadState_New(
|
// Export for _testinternalcapi
|
||||||
|
PyAPI_FUNC(PyThreadState *) _PyThreadState_New(
|
||||||
PyInterpreterState *interp,
|
PyInterpreterState *interp,
|
||||||
int whence);
|
int whence);
|
||||||
extern void _PyThreadState_Bind(PyThreadState *tstate);
|
extern void _PyThreadState_Bind(PyThreadState *tstate);
|
||||||
|
PyAPI_FUNC(PyThreadState *) _PyThreadState_NewBound(
|
||||||
|
PyInterpreterState *interp,
|
||||||
|
int whence);
|
||||||
extern PyThreadState * _PyThreadState_RemoveExcept(PyThreadState *tstate);
|
extern PyThreadState * _PyThreadState_RemoveExcept(PyThreadState *tstate);
|
||||||
extern void _PyThreadState_DeleteList(PyThreadState *list);
|
extern void _PyThreadState_DeleteList(PyThreadState *list);
|
||||||
extern void _PyThreadState_ClearMimallocHeaps(PyThreadState *tstate);
|
extern void _PyThreadState_ClearMimallocHeaps(PyThreadState *tstate);
|
||||||
|
|
|
@ -14,13 +14,6 @@ extern "C" {
|
||||||
#include "pycore_qsbr.h" // struct qsbr
|
#include "pycore_qsbr.h" // struct qsbr
|
||||||
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
_PyThreadState_SetWhence(PyThreadState *tstate, int whence)
|
|
||||||
{
|
|
||||||
tstate->_whence = whence;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Every PyThreadState is actually allocated as a _PyThreadStateImpl. The
|
// Every PyThreadState is actually allocated as a _PyThreadStateImpl. The
|
||||||
// PyThreadState fields are exposed as part of the C API, although most fields
|
// PyThreadState fields are exposed as part of the C API, although most fields
|
||||||
// are intended to be private. The _PyThreadStateImpl fields not exposed.
|
// are intended to be private. The _PyThreadStateImpl fields not exposed.
|
||||||
|
|
|
@ -1586,8 +1586,8 @@ exec_interpreter(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *res = NULL;
|
PyObject *res = NULL;
|
||||||
PyThreadState *tstate = PyThreadState_New(interp);
|
PyThreadState *tstate =
|
||||||
_PyThreadState_SetWhence(tstate, _PyThreadState_WHENCE_EXEC);
|
_PyThreadState_NewBound(interp, _PyThreadState_WHENCE_EXEC);
|
||||||
|
|
||||||
PyThreadState *save_tstate = PyThreadState_Swap(tstate);
|
PyThreadState *save_tstate = PyThreadState_Swap(tstate);
|
||||||
|
|
||||||
|
|
|
@ -1544,8 +1544,7 @@ _enter_session(_PyXI_session *session, PyInterpreterState *interp)
|
||||||
PyThreadState *tstate = PyThreadState_Get();
|
PyThreadState *tstate = PyThreadState_Get();
|
||||||
PyThreadState *prev = tstate;
|
PyThreadState *prev = tstate;
|
||||||
if (interp != tstate->interp) {
|
if (interp != tstate->interp) {
|
||||||
tstate = PyThreadState_New(interp);
|
tstate = _PyThreadState_NewBound(interp, _PyThreadState_WHENCE_EXEC);
|
||||||
_PyThreadState_SetWhence(tstate, _PyThreadState_WHENCE_EXEC);
|
|
||||||
// XXX Possible GILState issues?
|
// XXX Possible GILState issues?
|
||||||
session->prev_tstate = PyThreadState_Swap(tstate);
|
session->prev_tstate = PyThreadState_Swap(tstate);
|
||||||
assert(session->prev_tstate == prev);
|
assert(session->prev_tstate == prev);
|
||||||
|
@ -1895,8 +1894,7 @@ _PyXI_EndInterpreter(PyInterpreterState *interp,
|
||||||
tstate = cur_tstate;
|
tstate = cur_tstate;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tstate = PyThreadState_New(interp);
|
tstate = _PyThreadState_NewBound(interp, _PyThreadState_WHENCE_FINI);
|
||||||
_PyThreadState_SetWhence(tstate, _PyThreadState_WHENCE_INTERP);
|
|
||||||
assert(tstate != NULL);
|
assert(tstate != NULL);
|
||||||
save_tstate = PyThreadState_Swap(tstate);
|
save_tstate = PyThreadState_Swap(tstate);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1518,11 +1518,11 @@ switch_to_main_interpreter(PyThreadState *tstate)
|
||||||
if (_Py_IsMainInterpreter(tstate->interp)) {
|
if (_Py_IsMainInterpreter(tstate->interp)) {
|
||||||
return tstate;
|
return tstate;
|
||||||
}
|
}
|
||||||
PyThreadState *main_tstate = PyThreadState_New(_PyInterpreterState_Main());
|
PyThreadState *main_tstate = _PyThreadState_NewBound(
|
||||||
|
_PyInterpreterState_Main(), _PyThreadState_WHENCE_EXEC);
|
||||||
if (main_tstate == NULL) {
|
if (main_tstate == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
main_tstate->_whence = _PyThreadState_WHENCE_EXEC;
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
PyThreadState *old_tstate = PyThreadState_Swap(main_tstate);
|
PyThreadState *old_tstate = PyThreadState_Swap(main_tstate);
|
||||||
assert(old_tstate == tstate);
|
assert(old_tstate == tstate);
|
||||||
|
|
|
@ -677,7 +677,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
|
||||||
}
|
}
|
||||||
|
|
||||||
PyThreadState *tstate = _PyThreadState_New(interp,
|
PyThreadState *tstate = _PyThreadState_New(interp,
|
||||||
_PyThreadState_WHENCE_INTERP);
|
_PyThreadState_WHENCE_INIT);
|
||||||
if (tstate == NULL) {
|
if (tstate == NULL) {
|
||||||
return _PyStatus_ERR("can't make first thread");
|
return _PyStatus_ERR("can't make first thread");
|
||||||
}
|
}
|
||||||
|
@ -2233,7 +2233,7 @@ new_interpreter(PyThreadState **tstate_p,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
tstate = _PyThreadState_New(interp, _PyThreadState_WHENCE_INTERP);
|
tstate = _PyThreadState_New(interp, _PyThreadState_WHENCE_INIT);
|
||||||
if (tstate == NULL) {
|
if (tstate == NULL) {
|
||||||
status = _PyStatus_NO_MEMORY();
|
status = _PyStatus_NO_MEMORY();
|
||||||
goto error;
|
goto error;
|
||||||
|
|
|
@ -1293,9 +1293,8 @@ _PyInterpreterState_IDDecref(PyInterpreterState *interp)
|
||||||
PyThread_release_lock(interp->id_mutex);
|
PyThread_release_lock(interp->id_mutex);
|
||||||
|
|
||||||
if (refcount == 0 && interp->requires_idref) {
|
if (refcount == 0 && interp->requires_idref) {
|
||||||
PyThreadState *tstate = _PyThreadState_New(interp,
|
PyThreadState *tstate =
|
||||||
_PyThreadState_WHENCE_INTERP);
|
_PyThreadState_NewBound(interp, _PyThreadState_WHENCE_FINI);
|
||||||
_PyThreadState_Bind(tstate);
|
|
||||||
|
|
||||||
// XXX Possible GILState issues?
|
// XXX Possible GILState issues?
|
||||||
PyThreadState *save_tstate = _PyThreadState_Swap(runtime, tstate);
|
PyThreadState *save_tstate = _PyThreadState_Swap(runtime, tstate);
|
||||||
|
@ -1603,8 +1602,13 @@ new_threadstate(PyInterpreterState *interp, int whence)
|
||||||
PyThreadState *
|
PyThreadState *
|
||||||
PyThreadState_New(PyInterpreterState *interp)
|
PyThreadState_New(PyInterpreterState *interp)
|
||||||
{
|
{
|
||||||
PyThreadState *tstate = new_threadstate(interp,
|
return _PyThreadState_NewBound(interp, _PyThreadState_WHENCE_UNKNOWN);
|
||||||
_PyThreadState_WHENCE_UNKNOWN);
|
}
|
||||||
|
|
||||||
|
PyThreadState *
|
||||||
|
_PyThreadState_NewBound(PyInterpreterState *interp, int whence)
|
||||||
|
{
|
||||||
|
PyThreadState *tstate = new_threadstate(interp, whence);
|
||||||
if (tstate) {
|
if (tstate) {
|
||||||
bind_tstate(tstate);
|
bind_tstate(tstate);
|
||||||
// This makes sure there's a gilstate tstate bound
|
// This makes sure there's a gilstate tstate bound
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue