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
Added get_mut_unchecked #232
Conversation
For point 2, this does compile, but will it work as expected? (I don't have experience with crate
|
src/lib.rs
Outdated
/// the contents are acquired by (synchronized to) this thread. | ||
#[inline] | ||
#[cfg(not(feature = "critical_section"))] | ||
pub unsafe fn get_mut_unchecked(&self) -> &mut T { |
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.
What's the concrete use-case for this function? Given & -> &mut
signature, this seems more or less impossible to use correctly.
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.
My initial purpose was to implement wait_mut
, but I soon realized that wait_mut
seemed meaningless. But yes, it should be &mut -> &mut
here. Since there are get_unchecked
and get_mut
, will a get_mut_unchecked
look reasonable?
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.
I think that’s already available as get_mut().unwrap_unchecked()
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.
Then what about a shortcut that's self-explanatory? I've added a new commit to fix the function signature, but if you believe this is not necessary, feel free to close this PR. Thanks.
The effect of having `PhantomData<*mut Waiter>` is that the `OnceCell<T>` stops being `impl<T: Send> Send for OnceCell<T>`. But we want it to be `impl<T: Send> Send for OnceCell<T>`, because we manually mark it as such. Remove the `PhantomData` so we can also remove the manual `impl Send`.
This stuff is subtle, better not to rely on implicit behavior.
I added
get_mut_unchecked()
as it might help someone.Also, there are two things I'm considering but currently unsure about how to correctly implement:
wait_mut()
. However mutable reference across threads requires Mutex, but waiting with Mutex acquired will block other threads from initializing the value. Is there a case that this will make sense?get_mut_unchecked()
inimp_cs.rs
. This seems to require modification of the upstream cratecritical_section
, so I skipped it for now.