DateTime: use more relaxed ordering constraints#6027
Merged
davidhewitt merged 1 commit intomainfrom May 10, 2026
Merged
Conversation
Follow up to #6026
Tpt
commented
May 10, 2026
| #[inline] | ||
| pub unsafe fn PyDateTimeAPI() -> *mut PyDateTime_CAPI { | ||
| PyDateTimeAPI_impl.load(core::sync::atomic::Ordering::SeqCst) | ||
| PyDateTimeAPI_impl.load(Ordering::Acquire) |
Contributor
Author
There was a problem hiding this comment.
we don't need to expose any state here so "acquire" is fine
| /// Populates the `PyDateTimeAPI` object | ||
| pub unsafe fn PyDateTime_IMPORT() { | ||
| if PyDateTimeAPI_impl.load(Ordering::SeqCst).is_null() { | ||
| if PyDateTimeAPI_impl.load(Ordering::Relaxed).is_null() { |
Contributor
Author
There was a problem hiding this comment.
we just need to check if the value is null, "relaxed" is enough
| py_datetime_c_api, | ||
| Ordering::SeqCst, | ||
| Ordering::SeqCst, | ||
| Ordering::Release, |
Contributor
Author
There was a problem hiding this comment.
we don't need to acquire any state here on success (it's done by PyDateTime_IMPORT) so release is enough to expose the state to the other thread.
Similarly on error we don't need to expose anything (no visible change to the other thread) and PyDateTime_IMPORT will acquire the state.
davidhewitt
approved these changes
May 10, 2026
Member
davidhewitt
left a comment
There was a problem hiding this comment.
Fair enough, I was happy with strong ordering but also happy with good justification for tidier operations 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up to #6026