Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
546b934
Factor out add_threadstate().
ericsnowcurrently Mar 21, 2023
0bcd136
Add _PyThreadState_InitDetached().
ericsnowcurrently Mar 21, 2023
35d5310
Add _PyThreadState_ClearDetached().
ericsnowcurrently Mar 21, 2023
cba9e34
Add _PyRuntime.cached_objects.main_tstate.
ericsnowcurrently Mar 21, 2023
3b1bb8b
Add _Py_AcquireGlobalObjectsState() and _Py_ReleaseGlobalObjectsState().
ericsnowcurrently Mar 22, 2023
eb42aa1
Add _Py_AddToGlobalDict().
ericsnowcurrently Mar 22, 2023
4e9da2d
Drop _Py_AcquireGlobalObjectsState() and _Py_ReleaseGlobalObjectsStat…
ericsnowcurrently Mar 22, 2023
6216207
Add acquire_global_objects_lock() and release_global_objects_lock().
ericsnowcurrently Mar 22, 2023
3c007c0
Add some TODO comments.
ericsnowcurrently Mar 13, 2023
7d95514
Factor out store_interned().
ericsnowcurrently Mar 20, 2023
5c20b84
Store a thread state to use just for interned strings.
ericsnowcurrently Mar 20, 2023
a3ae02a
Always use the main interpreter when possibly resizing the interned d…
ericsnowcurrently Mar 20, 2023
d5fbc37
Use _PyRuntime.cached_objects.main_tstate instead.
ericsnowcurrently Mar 21, 2023
459325f
Add _PyThreadState_IsBound() and _PyThreadState_Unbind().
ericsnowcurrently Mar 21, 2023
4f25244
Make sure the one-off tstate is bound before using it.
ericsnowcurrently Mar 21, 2023
e68535a
Use _Py_AcquireGlobalObjectsState() in store_interned().
ericsnowcurrently Mar 22, 2023
22753b3
Use _Py_AddToGlobalDict().
ericsnowcurrently Mar 22, 2023
b649a84
Make objects stored in global containers immortal.
ericsnowcurrently Mar 20, 2023
9b0dc99
Immortalize the interned strings dict.
ericsnowcurrently Mar 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use _Py_AcquireGlobalObjectsState() in store_interned().
  • Loading branch information
ericsnowcurrently committed Mar 22, 2023
commit e68535ada0fe397c7d8c26e6f193b1e008122544
2 changes: 0 additions & 2 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) {
// PyThreadState functions

PyAPI_FUNC(PyThreadState *) _PyThreadState_New(PyInterpreterState *interp);
PyAPI_FUNC(int) _PyThreadState_IsBound(PyThreadState *tstate);
PyAPI_FUNC(void) _PyThreadState_Bind(PyThreadState *tstate);
PyAPI_FUNC(void) _PyThreadState_Unbind(PyThreadState *tstate);
// We keep this around exclusively for stable ABI compatibility.
PyAPI_FUNC(void) _PyThreadState_Init(
PyThreadState *tstate);
Expand Down
25 changes: 5 additions & 20 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -14585,41 +14585,26 @@ _PyUnicode_InitTypes(PyInterpreterState *interp)
}


static PyThreadState *
get_interned_tstate(void)
{
return &_PyRuntime.cached_objects.main_tstate;
}

static inline PyObject *
store_interned(PyObject *obj)
{
PyObject *interned = get_interned_dict();
assert(interned != NULL);

/* Swap to the main interpreter, if necessary. */
PyThreadState *oldts = NULL;
if (!_Py_IsMainInterpreter(_PyInterpreterState_GET())) {
PyThreadState *main_tstate = get_interned_tstate();
int bound = _PyThreadState_IsBound(main_tstate);
if (!bound) {
_PyThreadState_Bind(main_tstate);
}
oldts = PyThreadState_Swap(main_tstate);
assert(oldts != NULL);
if (!bound) {
_PyThreadState_Unbind(main_tstate);
}
}
PyInterpreterState *interp = _PyInterpreterState_GET();
PyThreadState *oldts = _Py_AcquireGlobalObjectsState(interp);

/* This might trigger a resize, which is why we must "acquire"
the global object state. */
PyObject *t = PyDict_SetDefault(interned, obj, obj);
if (t == NULL) {
PyErr_Clear();
}

/* Swap back. */
if (oldts != NULL) {
PyThreadState_Swap(oldts);
_Py_ReleaseGlobalObjectsState(oldts);
}

return t;
Expand Down
14 changes: 0 additions & 14 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1923,12 +1923,6 @@ PyThreadState_Swap(PyThreadState *newts)
}


int
_PyThreadState_IsBound(PyThreadState *tstate)
{
return tstate_is_bound(tstate);
}

void
_PyThreadState_Bind(PyThreadState *tstate)
{
Expand All @@ -1940,14 +1934,6 @@ _PyThreadState_Bind(PyThreadState *tstate)
}
}

void
_PyThreadState_Unbind(PyThreadState *tstate)
{
/* For now, we do not allow the initial tstate to be unbound. */
assert(gilstate_tss_get(tstate->interp->runtime) != tstate);
unbind_tstate(tstate);
}


/***********************************/
/* routines for advanced debuggers */
Expand Down