Skip to content
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

wrap UnsafeCell<MmapMut> with a mutex to fix Clippy lint on master #57

Closed
wants to merge 3 commits into from

Conversation

ylgrgyq
Copy link
Contributor

@ylgrgyq ylgrgyq commented Sep 14, 2023

According to my understanding, I tried to fix the problem mentioned here #56.

Please have a look and let me known if it is appropriate. Thanks

Cargo.toml Outdated Show resolved Hide resolved
@@ -13,7 +14,7 @@ use std::sync::Arc;
/// The view may be split into disjoint ranges, each of which will share the
/// underlying memory map.
pub struct MmapViewSync {
inner: Arc<UnsafeCell<MmapMut>>,
inner: Arc<Mutex<UnsafeCell<MmapMut>>>,
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could actually get rid of the UnsafeCell completely now that a Mutex protects from concurrent access?

Copy link
Contributor Author

@ylgrgyq ylgrgyq Sep 15, 2023

Choose a reason for hiding this comment

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

I tried to remove UnsafeCell completely, but in fn inner(&self) -> &MmapMut and fn inner_mut(&self) -> &mut MmapMut the compiler says cannot return value referencing temporary value. It seems we still need this UnsafeCell.

I'm a complete rookie for rust, please forgive my ignorance. 😅

@timvisee
Copy link
Member

timvisee commented Sep 25, 2023

@ylgrgyq Thanks for giving this a shot! This is a tricky problem.

After some consideration I decided to bypass the warning for now (#61). Using a Mutex is the right approach here as it would prevent having concurrent non-overlapping slice references.

I carefully inspected the code and do think all of it is sound in the current implementation.

I do believe that we should improve the architecture of this though to make it a lot harder to misuse.

@timvisee timvisee closed this Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants