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

Mmap flush does not require mutable reference, use corret mut ref self #58

Merged
merged 3 commits into from
Oct 2, 2023
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
15 changes: 11 additions & 4 deletions src/mmap_view_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,21 @@ impl MmapViewSync {

/// Get a reference to the inner mmap.
///
/// ## Unsafety
///
/// The caller must ensure that the file is not concurrently modified.
/// The caller must ensure that memory outside the `offset`/`len` range is not accessed.
fn inner(&self) -> &MmapMut {
unsafe { &*self.inner.get() }
}

/// Get a mutable reference to the inner mmap.
///
/// ## Unsafety
///
/// The caller must ensure that the file is not concurrently modified.
/// The caller must ensure that memory outside the `offset`/`len` range is not accessed.
#[allow(clippy::mut_from_ref)]
fn inner_mut(&self) -> &mut MmapMut {
fn inner_mut(&mut self) -> &mut MmapMut {
unsafe { &mut *self.inner.get() }
}

Expand All @@ -104,7 +109,7 @@ impl MmapViewSync {
/// map view are guaranteed to be durably stored. The file's metadata (including last
/// modification timestamp) may not be updated.
pub fn flush(&self) -> Result<()> {
self.inner_mut().flush_range(self.offset, self.len)
self.inner().flush_range(self.offset, self.len)
}

/// Returns the length of the memory map view.
Expand All @@ -127,7 +132,8 @@ impl MmapViewSync {
///
/// The caller must ensure that the file is not concurrently accessed.
pub unsafe fn as_mut_slice(&mut self) -> &mut [u8] {
&mut self.inner_mut()[self.offset..self.offset + self.len]
let (offset, len) = (self.offset, self.len);
&mut self.inner_mut()[offset..offset + len]
}

/// Clones the view of the memory map.
Expand Down Expand Up @@ -165,6 +171,7 @@ impl fmt::Debug for MmapViewSync {
}
}

#[cfg(test)]
unsafe impl Sync for MmapViewSync {}
unsafe impl Send for MmapViewSync {}

Expand Down