summaryrefslogtreecommitdiffstats
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-03-06 23:24:23 (GMT)
committerGitHub <noreply@github.com>2020-03-06 23:24:23 (GMT)
commit7b3c252dc7f44d4bdc4c7c82d225ebd09c78f520 (patch)
tree39b9496171733c94644e7a2671878fc3452526b8 /Python/pylifecycle.c
parent557287075c264d2458cd3e1b45e9b8ee5341e0a1 (diff)
downloadcpython-7b3c252dc7f44d4bdc4c7c82d225ebd09c78f520.zip
cpython-7b3c252dc7f44d4bdc4c7c82d225ebd09c78f520.tar.gz
cpython-7b3c252dc7f44d4bdc4c7c82d225ebd09c78f520.tar.bz2
bpo-39877: _PyRuntimeState.finalizing becomes atomic (GH-18816)
Convert _PyRuntimeState.finalizing field to an atomic variable: * Rename it to _finalizing * Change its type to _Py_atomic_address * Add _PyRuntimeState_GetFinalizing() and _PyRuntimeState_SetFinalizing() functions * Remove _Py_CURRENTLY_FINALIZING() function: replace it with testing directly _PyRuntimeState_GetFinalizing() value Convert _PyRuntimeState_GetThreadState() to static inline function.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 84ced42..23d74ee 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -103,7 +103,7 @@ _PyRuntime_Finalize(void)
int
_Py_IsFinalizing(void)
{
- return _PyRuntime.finalizing != NULL;
+ return _PyRuntimeState_GetFinalizing(&_PyRuntime) != NULL;
}
/* Hack to force loading of object files */
@@ -507,7 +507,7 @@ pycore_init_runtime(_PyRuntimeState *runtime,
* threads still hanging around from a previous Py_Initialize/Finalize
* pair :(
*/
- runtime->finalizing = NULL;
+ _PyRuntimeState_SetFinalizing(runtime, NULL);
PyStatus status = _Py_HashRandomization_Init(config);
if (_PyStatus_EXCEPTION(status)) {
@@ -1366,7 +1366,7 @@ Py_FinalizeEx(void)
/* Remaining threads (e.g. daemon threads) will automatically exit
after taking the GIL (in PyEval_RestoreThread()). */
- runtime->finalizing = tstate;
+ _PyRuntimeState_SetFinalizing(runtime, tstate);
runtime->initialized = 0;
runtime->core_initialized = 0;
@@ -2131,8 +2131,9 @@ static void
fatal_error_dump_runtime(FILE *stream, _PyRuntimeState *runtime)
{
fprintf(stream, "Python runtime state: ");
- if (runtime->finalizing) {
- fprintf(stream, "finalizing (tstate=%p)", runtime->finalizing);
+ PyThreadState *finalizing = _PyRuntimeState_GetFinalizing(runtime);
+ if (finalizing) {
+ fprintf(stream, "finalizing (tstate=%p)", finalizing);
}
else if (runtime->initialized) {
fprintf(stream, "initialized");