mirror of
https://github.com/python/cpython.git
synced 2025-10-14 18:59:46 +00:00
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.
This commit is contained in:
parent
45a24f54af
commit
d027787c8d
4 changed files with 45 additions and 48 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue