diff options
author | Sam Gross <colesbury@gmail.com> | 2025-02-27 08:27:54 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-27 13:27:54 +0000 |
commit | d027787c8d89f59a9f0b1d7cc6972f5e16ffc740 (patch) | |
tree | 1128b31a519ee0a1499fd6085881d5d0a107befd /Python/pystate.c | |
parent | 45a24f54af4a65c14cc15fc13d3258726e2fe73b (diff) | |
download | cpython-d027787c8d89f59a9f0b1d7cc6972f5e16ffc740.tar.gz cpython-d027787c8d89f59a9f0b1d7cc6972f5e16ffc740.zip |
gh-130421: Fix data race on timebase initialization (gh-130592)
Windows and macOS require precomputing a "timebase" in order to convert
OS timestamps into nanoseconds. Retrieve and compute this value during
runtime initialization to avoid data races when accessing the time.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index 09b83cdeb1f..9ebd9fdea60 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -20,6 +20,7 @@ #include "pycore_pystate.h" #include "pycore_runtime_init.h" // _PyRuntimeState_INIT #include "pycore_stackref.h" // Py_STACKREF_DEBUG +#include "pycore_time.h" // _PyTime_Init() #include "pycore_obmalloc.h" // _PyMem_obmalloc_state_on_heap() #include "pycore_uniqueid.h" // _PyObject_FinalizePerThreadRefcounts() @@ -461,6 +462,11 @@ _PyRuntimeState_Init(_PyRuntimeState *runtime) assert(!runtime->_initialized); } + PyStatus status = _PyTime_Init(&runtime->time); + if (_PyStatus_EXCEPTION(status)) { + return status; + } + if (gilstate_tss_init(runtime) != 0) { _PyRuntimeState_Fini(runtime); return _PyStatus_NO_MEMORY(); |