Skip to content

Commit

Permalink
Drop PyThreadState.whence.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Oct 11, 2023
1 parent 0ec39ff commit c40f162
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 37 deletions.
9 changes: 0 additions & 9 deletions Include/cpython/pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,6 @@ struct _ts {
/* padding to align to 4 bytes */
unsigned int :24;
} _status;
#ifdef Py_BUILD_CORE
# define _PyThreadState_WHENCE_NOTSET -1
# define _PyThreadState_WHENCE_UNKNOWN 0
# define _PyThreadState_WHENCE_INTERP 1
# define _PyThreadState_WHENCE_THREADING 2
# define _PyThreadState_WHENCE_GILSTATE 3
# define _PyThreadState_WHENCE_EXEC 4
#endif
int _whence;

int py_recursion_remaining;
int py_recursion_limit;
Expand Down
4 changes: 1 addition & 3 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) {

// PyThreadState functions

PyAPI_FUNC(PyThreadState *) _PyThreadState_New(
PyInterpreterState *interp,
int whence);
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(
Expand Down
1 change: 0 additions & 1 deletion Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ extern PyTypeObject _PyExc_MemoryError;

#define _PyThreadState_INIT \
{ \
._whence = _PyThreadState_WHENCE_NOTSET, \
.py_recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
.context_ver = 1, \
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
if (boot == NULL) {
return PyErr_NoMemory();
}
boot->tstate = _PyThreadState_New(interp, _PyThreadState_WHENCE_THREADING);
boot->tstate = _PyThreadState_New(interp);
if (boot->tstate == NULL) {
PyMem_RawFree(boot);
if (!PyErr_Occurred()) {
Expand Down
2 changes: 0 additions & 2 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ _run_script_in_interpreter(PyObject *mod, PyInterpreterState *interp,
PyThreadState *tstate = NULL;
if (interp != PyInterpreterState_Get()) {
tstate = PyThreadState_New(interp);
tstate->_whence = _PyThreadState_WHENCE_EXEC;
// XXX Possible GILState issues?
save_tstate = PyThreadState_Swap(tstate);
}
Expand Down Expand Up @@ -611,7 +610,6 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds)

// Destroy the interpreter.
PyThreadState *tstate = PyThreadState_New(interp);
tstate->_whence = _PyThreadState_WHENCE_INTERP;
// XXX Possible GILState issues?
PyThreadState *save_tstate = PyThreadState_Swap(tstate);
Py_EndInterpreter(tstate);
Expand Down
6 changes: 2 additions & 4 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
return status;
}

PyThreadState *tstate = _PyThreadState_New(interp,
_PyThreadState_WHENCE_INTERP);
PyThreadState *tstate = _PyThreadState_New(interp);
if (tstate == NULL) {
return _PyStatus_ERR("can't make first thread");
}
Expand Down Expand Up @@ -2026,8 +2025,7 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
return _PyStatus_OK();
}

PyThreadState *tstate = _PyThreadState_New(interp,
_PyThreadState_WHENCE_INTERP);
PyThreadState *tstate = _PyThreadState_New(interp);
if (tstate == NULL) {
PyInterpreterState_Delete(interp);
*tstate_p = NULL;
Expand Down
26 changes: 9 additions & 17 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,6 @@ _PyInterpreterState_SetNotRunningMain(PyInterpreterState *interp)
// thread, so it was set as threading._main_thread. (See gh-75698.)
// The thread has finished running the Python program so we mark
// the thread object as finished.
assert(tstate->_whence != _PyThreadState_WHENCE_THREADING);
tstate->on_delete(tstate->on_delete_data);
tstate->on_delete = NULL;
tstate->on_delete_data = NULL;
Expand Down Expand Up @@ -1159,8 +1158,7 @@ _PyInterpreterState_IDDecref(PyInterpreterState *interp)
PyThread_release_lock(interp->id_mutex);

if (refcount == 0 && interp->requires_idref) {
PyThreadState *tstate = _PyThreadState_New(interp,
_PyThreadState_WHENCE_INTERP);
PyThreadState *tstate = _PyThreadState_New(interp);
_PyThreadState_Bind(tstate);

// XXX Possible GILState issues?
Expand Down Expand Up @@ -1338,7 +1336,7 @@ free_threadstate(PyThreadState *tstate)

static void
init_threadstate(PyThreadState *tstate,
PyInterpreterState *interp, uint64_t id, int whence)
PyInterpreterState *interp, uint64_t id)
{
if (tstate->_status.initialized) {
Py_FatalError("thread state already initialized");
Expand All @@ -1351,10 +1349,6 @@ init_threadstate(PyThreadState *tstate,
assert(tstate->next == NULL);
assert(tstate->prev == NULL);

assert(tstate->_whence == _PyThreadState_WHENCE_NOTSET);
assert(whence >= 0 && whence <= _PyThreadState_WHENCE_EXEC);
tstate->_whence = whence;

assert(id > 0);
tstate->id = id;

Expand Down Expand Up @@ -1394,7 +1388,7 @@ add_threadstate(PyInterpreterState *interp, PyThreadState *tstate,
}

static PyThreadState *
new_threadstate(PyInterpreterState *interp, int whence)
new_threadstate(PyInterpreterState *interp)
{
PyThreadState *tstate;
_PyRuntimeState *runtime = interp->runtime;
Expand Down Expand Up @@ -1433,7 +1427,7 @@ new_threadstate(PyInterpreterState *interp, int whence)
sizeof(*tstate));
}

init_threadstate(tstate, interp, id, whence);
init_threadstate(tstate, interp, id);
add_threadstate(interp, tstate, old_head);

HEAD_UNLOCK(runtime);
Expand All @@ -1447,8 +1441,7 @@ new_threadstate(PyInterpreterState *interp, int whence)
PyThreadState *
PyThreadState_New(PyInterpreterState *interp)
{
PyThreadState *tstate = new_threadstate(interp,
_PyThreadState_WHENCE_UNKNOWN);
PyThreadState *tstate = new_threadstate(interp);
if (tstate) {
bind_tstate(tstate);
// This makes sure there's a gilstate tstate bound
Expand All @@ -1462,16 +1455,16 @@ PyThreadState_New(PyInterpreterState *interp)

// This must be followed by a call to _PyThreadState_Bind();
PyThreadState *
_PyThreadState_New(PyInterpreterState *interp, int whence)
_PyThreadState_New(PyInterpreterState *interp)
{
return new_threadstate(interp, whence);
return new_threadstate(interp);
}

// We keep this for stable ABI compabibility.
PyThreadState *
_PyThreadState_Prealloc(PyInterpreterState *interp)
{
return _PyThreadState_New(interp, _PyThreadState_WHENCE_UNKNOWN);
return _PyThreadState_New(interp);
}

// We keep this around for (accidental) stable ABI compatibility.
Expand Down Expand Up @@ -2235,8 +2228,7 @@ PyGILState_Ensure(void)
if (tcur == NULL) {
/* Create a new Python thread state for this thread */
// XXX Use PyInterpreterState_EnsureThreadState()?
tcur = new_threadstate(runtime->gilstate.autoInterpreterState,
_PyThreadState_WHENCE_GILSTATE);
tcur = new_threadstate(runtime->gilstate.autoInterpreterState);
if (tcur == NULL) {
Py_FatalError("Couldn't create thread-state for new thread");
}
Expand Down

0 comments on commit c40f162

Please sign in to comment.