mirror of
https://github.com/python/cpython.git
synced 2025-08-19 00:00:48 +00:00
gh-59956: Clarify Runtime State Status Expectations (gh-101308)
A PyThreadState can be in one of many states in its lifecycle, represented by some status value. Those statuses haven't been particularly clear, so we're addressing that here. Specifically: * made the distinct lifecycle statuses clear on PyThreadState * identified expectations of how various lifecycle-related functions relate to status * noted the various places where those expectations don't match the actual behavior At some point we'll need to address the mismatches. (This change also includes some cleanup.) https://github.com/python/cpython/issues/59956
This commit is contained in:
parent
ea232716d3
commit
e11fc032a7
6 changed files with 426 additions and 176 deletions
|
@ -119,7 +119,30 @@ struct _ts {
|
|||
PyThreadState *next;
|
||||
PyInterpreterState *interp;
|
||||
|
||||
int _status;
|
||||
struct {
|
||||
/* Has been initialized to a safe state.
|
||||
|
||||
In order to be effective, this must be set to 0 during or right
|
||||
after allocation. */
|
||||
unsigned int initialized:1;
|
||||
|
||||
/* Has been bound to an OS thread. */
|
||||
unsigned int bound:1;
|
||||
/* Has been unbound from its OS thread. */
|
||||
unsigned int unbound:1;
|
||||
/* Has been bound aa current for the GILState API. */
|
||||
unsigned int bound_gilstate:1;
|
||||
/* Currently in use (maybe holds the GIL). */
|
||||
unsigned int active:1;
|
||||
|
||||
/* various stages of finalization */
|
||||
unsigned int finalizing:1;
|
||||
unsigned int cleared:1;
|
||||
unsigned int finalized:1;
|
||||
|
||||
/* padding to align to 4 bytes */
|
||||
unsigned int :24;
|
||||
} _status;
|
||||
|
||||
int py_recursion_remaining;
|
||||
int py_recursion_limit;
|
||||
|
@ -245,6 +268,8 @@ struct _ts {
|
|||
// Alias for backward compatibility with Python 3.8
|
||||
#define _PyInterpreterState_Get PyInterpreterState_Get
|
||||
|
||||
/* An alias for the internal _PyThreadState_New(),
|
||||
kept for stable ABI compatibility. */
|
||||
PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);
|
||||
|
||||
/* Similar to PyThreadState_Get(), but don't issue a fatal error
|
||||
|
|
|
@ -120,13 +120,12 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) {
|
|||
|
||||
// PyThreadState functions
|
||||
|
||||
PyAPI_FUNC(PyThreadState *) _PyThreadState_New(PyInterpreterState *interp);
|
||||
PyAPI_FUNC(void) _PyThreadState_Bind(PyThreadState *tstate);
|
||||
// We keep this around exclusively for stable ABI compatibility.
|
||||
PyAPI_FUNC(void) _PyThreadState_Init(
|
||||
PyThreadState *tstate);
|
||||
PyAPI_FUNC(void) _PyThreadState_DeleteExcept(
|
||||
_PyRuntimeState *runtime,
|
||||
PyThreadState *tstate);
|
||||
PyAPI_FUNC(void) _PyThreadState_DeleteExcept(PyThreadState *tstate);
|
||||
|
||||
|
||||
static inline void
|
||||
|
@ -139,18 +138,6 @@ _PyThreadState_UpdateTracingState(PyThreadState *tstate)
|
|||
}
|
||||
|
||||
|
||||
/* PyThreadState status */
|
||||
|
||||
#define PyThreadState_UNINITIALIZED 0
|
||||
/* Has been initialized to a safe state.
|
||||
|
||||
In order to be effective, this must be set to 0 during or right
|
||||
after allocation. */
|
||||
#define PyThreadState_INITIALIZED 1
|
||||
#define PyThreadState_BOUND 2
|
||||
#define PyThreadState_UNBOUND 3
|
||||
|
||||
|
||||
/* Other */
|
||||
|
||||
PyAPI_FUNC(PyThreadState *) _PyThreadState_Swap(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue