-
Notifications
You must be signed in to change notification settings - Fork 792
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
Add critical section API wrappers #4587
Conversation
Test currently fails on emscripten. |
src/sync.rs
Outdated
let _guard = unsafe { | ||
let mut section = std::mem::zeroed(); | ||
crate::ffi::PyCriticalSection_Begin(&mut section, object.as_ptr()); | ||
Guard(section) | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not be moving this
let _guard = unsafe { | |
let mut section = std::mem::zeroed(); | |
crate::ffi::PyCriticalSection_Begin(&mut section, object.as_ptr()); | |
Guard(section) | |
}; | |
let mut guard = Guard(unsafe {std::mem::zeroed()}); | |
unsafe { crate::ffi::PyCriticalSection_Begin(&mut guard.section, object.as_ptr()) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add PhantomPinned
to PyCriticalSection
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add
PhantomPinned
toPyCriticalSection
?
It doesn't really matter in this case.
Implementing a type that "needs pinning" requires unsafe code, and writing code that needs pinned types also requires unsafe code. Pin is just a way to let safe code carry that promise between two pieces of unsafe code. The latter doesn't happen here.
Added the ci-build-full label to see if there are any other corner cases in the full tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks great, thanks!
ping @bschoenmaeckers for your other PR.
Adds
Default
impls forffi::PyCriticalSection
andffi::PyCriticalSection2
. These are needed to actually use these structs, since the fields are private.I'm not sure how to write a test to check that critical sections are closed when a panic happens. I think I'd need to instrument the RAII guard for that to work, and that seems wrong to me.
I'd also appreciate suggestions for an example to go in the docstring.