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 src/sync/critical_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ where
#[cfg(Py_GIL_DISABLED)]
{
let mut guard = CSGuard(unsafe { core::mem::zeroed() });
unsafe { crate::ffi::PyCriticalSection_BeginMutex(&mut guard.0, &mut *mutex.mutex.get()) };
unsafe { crate::ffi::PyCriticalSection_BeginMutex(&raw mut guard.0, mutex.mutex.get()) };
f(EnteredCriticalSection(&mutex.data))
}
#[cfg(not(Py_GIL_DISABLED))]
Expand Down Expand Up @@ -243,9 +243,9 @@ where
let mut guard = CS2Guard(unsafe { core::mem::zeroed() });
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

While we're here, I think we might be able to replace these core::mem::zeroed() with MaybeUninit of some form, to avoid needing to zero-intialize the structures at each critical section entry.

Looks like the C headers don't zero-initialize:

https://github.com/python/cpython/blob/a7ed0c9e1dee1397e80e2e0d90d110155da2bc30/Include/critical_section.h#L74-L90

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

(Possibly better to defer this to a separate PR given correctness / performance implications are not related to the exact diff here.)

unsafe {
crate::ffi::PyCriticalSection2_BeginMutex(
&mut guard.0,
&mut *m1.mutex.get(),
&mut *m2.mutex.get(),
&raw mut guard.0,
m1.mutex.get(),
m2.mutex.get(),
)
};
f(
Expand Down
Loading