Skip to content

DateTime: use more relaxed ordering constraints#6027

Merged
davidhewitt merged 1 commit intomainfrom
tpt/datetime-ordering
May 10, 2026
Merged

DateTime: use more relaxed ordering constraints#6027
davidhewitt merged 1 commit intomainfrom
tpt/datetime-ordering

Conversation

@Tpt
Copy link
Copy Markdown
Contributor

@Tpt Tpt commented May 10, 2026

Follow up to #6026

Comment thread pyo3-ffi/src/datetime.rs
#[inline]
pub unsafe fn PyDateTimeAPI() -> *mut PyDateTime_CAPI {
PyDateTimeAPI_impl.load(core::sync::atomic::Ordering::SeqCst)
PyDateTimeAPI_impl.load(Ordering::Acquire)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we don't need to expose any state here so "acquire" is fine

Comment thread pyo3-ffi/src/datetime.rs
/// 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() {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we just need to check if the value is null, "relaxed" is enough

Comment thread pyo3-ffi/src/datetime.rs
py_datetime_c_api,
Ordering::SeqCst,
Ordering::SeqCst,
Ordering::Release,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@Tpt Tpt added the CI-skip-changelog Skip checking changelog entry label May 10, 2026
Copy link
Copy Markdown
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Fair enough, I was happy with strong ordering but also happy with good justification for tidier operations 👍

@davidhewitt davidhewitt enabled auto-merge May 10, 2026 13:32
@davidhewitt davidhewitt added this pull request to the merge queue May 10, 2026
Merged via the queue into main with commit 898e2e8 May 10, 2026
46 of 47 checks passed
@davidhewitt davidhewitt deleted the tpt/datetime-ordering branch May 10, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI-skip-changelog Skip checking changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants