10000 gh-130421: Fix data race on timebase initialization by colesbury · Pull Request #130592 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-130421: Fix data race on timebase initialization #130592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 27, 2025

Conversation

colesbury
Copy link
Contributor
@colesbury colesbury commented Feb 26, 2025

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.

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.
@colesbury colesbury marked this pull request as ready for review February 26, 2025 19:55
@colesbury colesbury requested a review from vstinner February 26, 2025 19:55
Copy link
Member
@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I just suggest using _PyStatus_ERR() instead.

It's a bit unfortunate to waste one byte on non-Windows/non-macOS platforms, but I understand the desire to make the code more regular.

Python/pytime.c Outdated
"invalid QueryPerformanceFrequency");
}
return -1;
return PyStatus_Error("invalid QueryPerformanceFrequency");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use _PyStatus_ERR() instead: it stores the name of the current function, which gives more information in case of failure.

Suggested change
return PyStatus_Error("invalid QueryPerformanceFrequency");
return _PyStatus_ERR("invalid QueryPerformanceFrequency");

Same remark below (py_mach_timebase_info).

@colesbury colesbury enabled auto-merge (squash) February 27, 2025 13:04
@colesbury colesbury merged commit d027787 into python:main Feb 27, 2025
41 checks passed
@colesbury colesbury deleted the gh-130421-timebase branch February 27, 2025 13:29
seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
…30592)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0