Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pyo3-ffi/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,12 @@ pub const PyDateTime_CAPSULE_NAME: &CStr = c"datetime.datetime_CAPI";
/// `PyDateTime_IMPORT` is called
#[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

}

/// 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

// PyPy expects the C-API to be initialized via PyDateTime_Import, so trying to use
// `PyCapsule_Import` will behave unexpectedly in pypy.
#[cfg(PyPy)]
Expand All @@ -628,8 +628,8 @@ pub unsafe fn PyDateTime_IMPORT() {
let _ = PyDateTimeAPI_impl.compare_exchange(
ptr::null_mut(),
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.

Ordering::Relaxed,
);
}
}
Expand Down
Loading